Thread: Data Reader
View Single Post
  #1 (permalink)  
Old July 3rd, 2009, 02:25 PM
Banishah Banishah is offline
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....
Reply With Quote