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....
|