i'm creating a window form and i run this code ,firsttime i was add avalue in datagirdview correctly but the secondtime i'm trying to add a value in datagirdview but getting this error
There is no row at position 1. this line
double b = Convert.ToDouble(dt.Rows[count][1]);
int count = 0;
private void button1_Click(object sender, EventArgs e)
{
id = Convert.ToInt32(txt_item.Text);
date = DateTime.Now;
string q = "select pro_name , amount from Product where pro_id = " + id ;
dt = g.selectQuery(q);
if (dt.Rows.Count > 0)
{
if (!dt.Columns.Contains("Quantity selected"))
{
dt.Columns.Add("Qty");
}
if (!dt.Columns.Contains("Total"))
{
dt.Columns.Add("Total");
}
double b = Convert.ToDouble(dt.Rows[count][1]);
dt.Rows[count][2] = 1;
dt.Rows[count][3] = 1*b;
dataGridView1.DataSource = dt;
count++;
}
}