Problem :
I want to add the data as one by one row to my datagridview. But I am facing the following error:
"Index was out of range. Must be non-negative and less than the size of the collection parameter name: index"
Why am I facing this error ? Do I need to make anychanges in my following code:
String Sqlstr = "select ItemName from Item where ItemID = '" + tbItemID.Text + "'";
db.DataRead(Sqlstr);
string ItemName = db.dr["ItemName"].ToString();
DataGridView myDataGridView = new DataGridView();
myDataGridView.Columns[0].Name = "ItemID";
myDataGridView.Columns[1].Name = "ItemName";
myDataGridView.Columns[2].Name = "Qty";
myDataGridView.Columns[3].Name = "UnitPrice";
myDataGridView.Columns[4].Name = "Amount";
string ColumOne = tbItemID.Text;
string ColumTwo = ItemName;
string ColumThree = tbQuantity.Text;
string ColumFour = Convert.ToString(UnitPrice);
string ColumFive = Convert.ToString(sum);
string[] row = new string[]{ ColumOne, ColumTwo, ColumThree, ColumFour, ColumFive };
myDataGridView.Rows.Add(row);