get value from SQL server 2005 select statement with datareader

I just want a simple datareader, that i can read the value returned from a select statement executed on a SQL server 2005 db.

 The code below should work in, but email[calc]= rdr[0].ToString(); when i want to read some data a get a exception saying:

System.InvalidOperationException was unhandled by user code
  Message="Invalid attempt to read when no data is present."
  Source="System.Data"
  StackTrace:
       at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i)
       at System.Data.SqlClient.SqlDataReader.get_Item(Int32 i)
       at _Default.Login_Click(Object sender, EventArgs e) in d:\My Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx.cs:line 47
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

 If anybody could  advise me where my stupid mistake is then i would highly appreciate it!

 

        SqlConnection conn = new SqlConnection(getConnection());
        SqlDataReader rdr = null;

        SqlCommand cmd = new SqlCommand();

        cmd.CommandText = "SELECT * FROM Customer";
        cmd.CommandType = CommandType.Text;
        cmd.Connection = conn;

        try
        {
            conn.Open();
               
            rdr = cmd.ExecuteReader();
            
            int calc = 0;

            Boolean login = false;
            string[] email = new string[100];
            object[] password = new object[100];

            while (rdr.HasRows) // or rdr.Read();
            {
                rdr.Read();
                email[calc]= rdr[0].ToString();
                password[calc] = rdr["Password"].ToString();
                if (UserName.Text.Equals(email[calc]) && Password.Text.Equals(password[calc]))
                {
                    login = true;
                }
                calc++;
            }

        }
        finally
        {
            rdr.Close();
        }

 

 

thanks.... 

0
kennkikkenborg
11/6/2006 4:32:24 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

1 Replies
634 Views

Similar Articles

[PageSpeed] 5
Get it on Google Play
Get it on Apple App Store

Try this:

           if (rdr.HasRows) // or rdr.Read(); 
            {
                while(rdr.Read())
                {
                  email[calc]= rdr[0].ToString();
                   password[calc] = rdr["Password"].ToString();
                  if (UserName.Text.Equals(email[calc]) && Password.Text.Equals(password[calc]))
                  {
                    login = true;
                  }
                  calc++;
                }
            }
 Hope this helps.
Sincerely,
Young Fang
0
yyy8347
11/7/2006 1:58:16 AM
Reply:

Similar Artilces:

Reuse derived columns in same SQL Select statement under SQL Server 2005
Hello, Our agency is in the process of migrating our Sybase Adaptive Server Anywhere 7.0 databases to Microsoft SQL Server 2005. We are currently using PowerBuilder 10.5. We have several datawindows that reuse SQL computed fields (derived columns) in the same SQL Select statement. Here is an example: select institution_code, incident_number, sequence, final_review_date, ts_status_code, idoc_number, (CASE WHEN coalesce(s.recommended_verbal,'N') <> coalesce(s.final_verbal,'N') then 1 else 0 end) as c_verbal, (CASE WHEN coalesce(s.recomme...

SQL Server Reporting Services for SQL SERVER 2000 AND Visual Studio.NET 2005 .NET 2.0
Hi, Which version of SQl Server Reporting Services will work with SQL SERVER 2000 in pararrel with ASP.NET 2.0 (.NET 2.0 framework)?  Thanks, Azam HighOnCodingWanna get high! Hi, Okay I got the answer. Yes, we can use the SQL SERVER 2005 Reporting Services with SQL SERVER 2000. HighOnCodingWanna get high! ...

Converting MDF files (SQL Server Express) to SQL Server 2005 WITHOUT having to buy SQL Server 2005 (I have Express). Personal WebSite Starter Kit
Hi (and HELP!),   I downloaded the Personal WebSite Starter Kit and got it working no problem on my local machine.  But I've had nothing but frustration trying to get it up and running on a webhosting site.  I picked hostmysite.com which uses SQL Server 2005.  I was under the impression that it wouldn't be that big a deal to convert the .MDF files that Sql Server Express uses to a SQL Server 2005 database.  I tried using SQL Server Management Studio Express.  I was able to "see" my remote database on hostmysite.com, but I was not able to import the .mdf files ...

Converting MDF files (SQL Server Express) to SQL Server 2005 WITHOUT having to buy SQL Server 2005 (I have Express). Personal WebSite Starter Kit
Hi,Basically i built a webpage with Login and it's working well from my local machine.Right now, i'm using Database Publishing Wizard. the problem is how do i convert.MDF files to .SQL 2005 to get my database publish in the internet? thanks  Place your .MDF file in the App_Data directory, change the connection string accordingly and then publish your web site. ----------------------------------------------------------Please click Mark As Answer if this helped in solving your problem.  Please click "Mark As Answer" if this hepled in solving your problem. ...

Converting MDF files (SQL Server Express) to SQL Server 2005 WITHOUT having to buy SQL Server 2005 (I have Express). Personal WebSite Starter Kit
Hi (and HELP!),   I downloaded the Personal WebSite Starter Kit and got it working no problem on my local machine.  But I've had nothing but frustration trying to get it up and running on a webhosting site.  I picked hostmysite.com which uses SQL Server 2005.  I was under the impression that it wouldn't be that big a deal to convert the .MDF files that Sql Server Express uses to a SQL Server 2005 database.  I tried using SQL Server Management Studio Express.  I was able to "see" my remote database on hostmysite.com, but I was not able to import the .mdf file...

SQL server 2005 and SQL server 2005 lite
Hi, I have a web site hosted at a hosting company.. I'm in the process of designing a web site which has some forms that are going to hit a database, etc.. for a small company.. This small company has it's own Web server, and when I'm finished I'll copy the finsihed product to their IIS web server, etc.. Well, I have SQL server 2005 full edition as part of my web hosting, but I'm going to have to use SQL server Lite for the end user / client since they don't have SQL server. So, I'm wondering if I can do my work on MY remote host using the full edition of SQL server 2005, and then copy to th...

SQL Server 2005 Installation problems with SQL Server Express & SQL Server 2000
Hi Guys, I have had SQL Server Express and Sql Server Management Studio Express installed on my machine for some time and recently tried to install a trial of SQL Server 2005 as well.  (Yes, I'm migrating from Visual Studio Express to Visual Studio Professional, just as in tended!) Everything went fine except that nothing seemed to be installed.  I searched in all the obvious places - both on the Start/Programs menu and on the hard-drive: nothing. A check under Add/Remove Programs showed that Sql Server 2005 Express was installed, but called SQL Server 2005. So after a number o...

Having trouble getting SP from sql Server 2005 to work in SQL Server 2000
I am getting an error saying incorrect syntax near fIt works in SQL Server 2005, but I cannot get it to work in SQL Server 2000  The error appears to be in the section that I marked in Bold. CREATE PROCEDURE [dbo].[pe_getReport]  -- Add the parameters for the stored procedure here    @BranchID INT,    @InvestorID INT,    @Status INT,    @QCAssigned INT,    @LoanOfficer nvarChar(40),    @FromCloseDate DateTime,    @ToCloseDate DateTime,    @Orde...

This version of Microsoft Sql Server Management Studio can only be used to connect to Sql Server 2000 and Sql Server 2005 servers
When I connect SQL Server 2005 to a remote database i get the error: "This version of Microsoft Sql Server Management Studio can only be used to connect to Sql Server 2000 and Sql Server 2005 servers". Can I confirm it is because: the remote db is of SQL Server 2008? There is a soln mentioned in http://forums.asp.net/t/1324047.aspx Did anybody try this (installing 2008 express: http://www.microsoft.com/express/sql/download/)? I am just checking again, whether it will disturb my existing SQL Server installation, in any means...? Though it is mentioned that it will g...

SQL Server 2000 and SQL Server 2005 in the same server
Can enyone please send me a link to a white paper explaining how to run both SQL Server 2000 and 2005 in the same machine?Thanks. I don't know about the white paper but I had both running on my machine for a while by making the SQL 2000 a named instance. So for SQL 2005 connection strings my server name was (local) while for SQL 200 using the named instance it was (local)\joesql where joesql was the instance nameHope it helps,Joe http://www.joeaudette.comhttp://www.mojoportal.com...

I cannot stop Visual Studio.NET 2005 from looking for SQL Server 2005 instead of SQL 2000
I would like to know how to set SQL2000 as the default database server when running any webapplication. I have installed Visual Studio.NET and SQL Server 2000 locally in my laptop.  But anytime I want to run a webapplication I am getting the following error:System.Data.SqlClient.SqlException was unhandled by user code  Class=20  ErrorCode=-2146232060  LineNumber=0  Message="An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server doe...

Confliction between SQL Server 2005 and SQL Server 2005 Express Edition
Hi,   My objective is using a single DB file (mdf file)  + SQL Server Express 2005 to run my program   I got two softwares here, Visual Studio 2005 and SQL Server 2005. Firstly, I installed Visual Studio 2005, normally the SQL Server 2005 Express Edition will be installed with this software. After finishing the installation. I opened a new project and try to open a DB file (.mdf) from Visual Studio 2005, it works. The problem is that I can't restore the mdf file from an old database file since it lose a lot of functions that appear in SQL Server 2000 / SQL Server 2005. ...

Move from SQL Server 2000 to SQL Server 2005 with VS 2005
 We have a new database server for SQL Server 2005.  To use our old VS 2005 websites, which were connected toanother database server with SQL Server 2000, what should I do?  Just change the server name of the connection stringin the Source code and/or Web.config?  My preliminary testing seemed to be not effective.TIA,Jeffrey wonjartran:  We have a new database server for SQL Server 2005.  To use our old VS 2005 websites, which were connected toanother database server with SQL Server 2000, what should I do?  Just change the server name of the connectio...

Moving SQL Server 2005 Database to SQL Server 2005 Express
Hi, I have SQL Server 2005 in my Development machine but the hosting server has only SQL server 2005 Express. I was wondering if I develop the DB in SQL server 2005 would be able to move/deploy it to SQL Server Express in the production server? If so how? Can I just generate the script and then run it on the productions server? Or there is a better/easier way? Thanks in advanceShuaib----------------------- I don't anticipate any problems creating database in SQL Server 2005 and moving it to Express. If you need to generate the script to create an empty shell (no d...

Web resources about - get value from SQL server 2005 select statement with datareader - asp.net.sql-datasource

Highest Voted 'entity-framework' Questions - Stack Overflow
Q&A for professional and enthusiast programmers

Microsoft Data Access Components - Wikipedia, the free encyclopedia
This article has an unclear citation style . The references used may be made clearer with a different or consistent style of citation , footnoting ...

E-Trade and eBay Join Ad Age Data Conference October 28-29
... and more. Be sure to reserve your spot today. We're offering a limited 10% discount this week only to those who use the discount code DATAREADER. ...

Windows 8 WriteableBitmap Pixel Arrays in C# and C++
August 5, 2012 Roscoe, N.Y. Sometimes I thiink of myself as a scientist who studies operating systems. Although these operating systems form ...

Latest Updates
Latest Updates - Free source code and tutorials for Software developers and Architects.; Updated: 15 Feb 2013

moredotnet
M ore d otnet .NET Interview Questions, ASP.NET, C#, VB.NET, XML, SQL Check Out http://www.dotnetUncle.com √ .NET NOTES OOPS in .NET .NET ...

The Weekly Source Code 51 - Asynchronous Database Access and LINQ to SQL Fun - Scott Hanselman
Scott Hanselman on Programming, User Experience, The Zen of Computers and Life in General

Should you use Entity Framework for .NET applications?
I have been working on a project which I thought would be simpler than it turned out to be – nothing new there, most software projects are like ...

MSDN Magazine December 2001
The Windows XP kernel includes a number of improvements over Windows 2000 that promote better scalability and overall performance. This article ...

A Map for the Microsoft Application Development Platform
... N-Tier Remote Data Security Silverlight SQL Azure SQL Server Streaming XML Features ADO.NET DataSet ADO.NET DataTable ADO.NET DataReader ...

Resources last updated: 12/8/2015 2:32:46 AM