p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 3rd, 2009, 02:25 PM
Authorized User
Points: 141, Level: 2
Points: 141, Level: 2 Points: 141, Level: 2 Points: 141, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2009
Posts: 30
Thanks: 13
Thanked 0 Times in 0 Posts
Default Data Reader

Hi...i am using data reader to search the company name,contact name and phone by using customerID....but there is an error....see down for the error...i highlight it


protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conCust;
SqlCommand cmdSelect;
SqlDataReader dtrCustomer;
string connStr = ConfigurationManager.ConnectionStrings["ConnectionCust"].ConnectionString;
conCust = newSqlConnection(connStr);
conCust.Open();
cmdSelect = newSqlCommand("Select CustomerID From Customers", conCust);
dtrCustomer = cmdSelect.ExecuteReader();
while (dtrCustomer.Read())
{

Label2.Text = Convert.ToString(dtrCustomer["CompanyName"]);\\error:index out of range exception)
Label3.Text = Convert.ToString(dtrCustomer["ContactName"]);error:index out of range exception)
Label4.Text = dtrCustomer["Phone"].ToString();error(index out of range exception)
}
dtrCustomer.Close();
conCust.Close();
}

why index out of range exception?....i did not declare any array....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old July 3rd, 2009, 02:58 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,237, Level: 27
Points: 4,237, Level: 27 Points: 4,237, Level: 27 Points: 4,237, Level: 27
Activity: 48%
Activity: 48% Activity: 48% Activity: 48%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 803
Thanks: 12
Thanked 139 Times in 139 Posts
Default

You are only selecting the CustomerID field in your command statement

cmdSelect = newSqlCommand("Select CustomerID From Customers", conCust);

Therefore, CompanyName, ContactName, and Phone are not contained in the reader.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
The Following User Says Thank You to Lee Dumond For This Useful Post:
Banishah (July 3rd, 2009)
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter6.1.3 :Data Reader Source johe BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 0 November 28th, 2008 04:35 AM
Data reader checking.... janees ASP.NET 1.0 and 1.1 Professional 1 March 11th, 2007 07:09 AM
oracle data reader silvia C# 10 February 2nd, 2006 07:30 AM
Fill data set from data reader sunil menghani ADO.NET 3 March 29th, 2005 07:08 AM
extracting a value from a data reader Morrislgn ASP.NET 1.1 6 February 27th, 2004 02:02 PM



All times are GMT -4. The time now is 12:55 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc