Exception unhandled
string cellvalue = dataGridView1["customer_id", index].Value.ToString();
SqlCommand cmdd = new SqlCommand("SELECT * FROM bike_sales WHERE customer_id='" + cellvalue + "'", my);
SqlDataReader rdd = cmd.ExecuteReader();
rdd.Read();
up.textBox26.Text = rdd["stock_id"].ToString();,,,,,,,,,,,,,,,,,,,,,,here i got error index out of range exception unhandled
whats wrong with it hlp plz

VulpesRank #55 · 29.2K reputationPosted Dec 11, 2013, 4:05 AM EST
So are you sure that the name of this column is correct?
ta mu198 reputationPosted Dec 11, 2013, 4:42 AM EST
private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
my.Open();
string cellvalue = dataGridView1["customer_id", index].Value.ToString();
SqlCommand cmd = new SqlCommand("SELECT * FROM addcustomer WHERE customer_id='"+cellvalue+"'",my);
SqlDataReader rd = cmd.ExecuteReader();
rd.Read();
up.textBox1.Text = rd["customer_id"].ToString();
up.textBox2.Text = rd["Name"].ToString();
up.textBox3.Text = rd["Father_name"].ToString();
up.textBox4.Text = rd["CNIC_No"].ToString();
up.textBox5.Text = rd["Phone_No"].ToString();
up.textBox6.Text = rd["Occupation"].ToString();
up.textBox7.Text = rd["Address"].ToString();
up.textBox17.Text = rd["Refrence_1_Name"].ToString();
up.textBox18.Text = rd["Refrence_1_Father_name"].ToString();
up.textBox19.Text = rd["Refrence_1_Phone_No"].ToString();
up.textBox20.Text = rd["Refrence_1_Address"].ToString();
up.textBox21.Text = rd["Refrence_2_Name"].ToString();
up.textBox22.Text = rd["Refrence_2_Father_name"].ToString();
up.textBox23.Text = rd["Refrence_2_Phone_No"].ToString();
up.textBox24.Text = rd["Refrence_2_Address"].ToString();
rd.Close();
SqlCommand cmdd = new SqlCommand("SELECT * FROM bike_sales WHERE STOCK_ID='" + cellvalue + "'", my);
SqlDataReader rdd = cmd.ExecuteReader();
rdd.Read();
up.textBox26.Text = rdd["STOCK_ID"].ToString();
up.textBox12.Text = rdd["Advance"].ToString();
up.textBox13.Text = rdd["Due_amount"].ToString();
up.textBox14.Text = rdd["One_installment_price"].ToString();
up.textBox15.Text = rdd["No_of_installments"].ToString();
up.dateTimePicker1.Value = System.Convert.ToDateTime(rdd["sale_date"]);
rdd.Close();
SqlCommand cmds = new SqlCommand("SELECT * FROM add_stock WHERE stock_id='" + up.textBox26 + "'", my);
SqlDataReader rds = cmd.ExecuteReader();
rds.Read();
up.textBox16.Text = rds["bike_model"].ToString();
up.textBox8.Text = rds["Engine_No"].ToString();
up.textBox9.Text = rds["Frame_No"].ToString();
up.textBox25.Text = rds["purchase_price"].ToString();
up.textBox10.Text = rds["Registration_No"].ToString();
up.textBox11.Text = rds["Sale_price"].ToString();
rds.Close();
my.Close();
}
VulpesRank #55 · 29.2K reputationPosted Dec 11, 2013, 4:54 AM EST
SqlCommand cmdd = new SqlCommand("SELECT * FROM bike_sales WHERE STOCK_ID='" + cellvalue + "'", my);
should be:
SqlCommand cmdd = new SqlCommand("SELECT * FROM bike_sales WHERE CUSTOMER_ID='" + cellvalue + "'", my);
which appears to be what you had in the first place but, otherwise, it looks OK on a first read through.
VulpesRank #55 · 29.2K reputationPosted Dec 11, 2013, 5:32 AM EST
http://msdn.microsoft.com/en-us/library/f01t4cfy(v=vs.110).aspx
In view of what it says in the Remarks section, I think the safest thing to do is to use the same casing (i.e. upper case) for the column names as in the database table itself, just in case this could be causing a problem somewhere along the line.
ta mu198 reputationPosted Dec 13, 2013, 8:20 PM EST
ta mu198 reputationPosted Dec 14, 2013, 3:15 AM EST