Hello All:
I am trying to get a webcontrols DataGrid(NET2.0) to update/delete. I have this code in the DeleteCommand event in the code behind and its throwing this exception:
System.IndexOutOfRangeException: An SqlParameter with ParameterName '@RowID' is not contained by this SqlParameterCollection.
SqlConnection conn = new SqlConnection(connString);
SqlCommand mySqlCommand = conn.CreateCommand();
mySqlCommand.Parameters["@RowID"].Value = DataGrid1.DataKeys[e.Item.ItemIndex]; //Throws //IndexOutOfRange exception
mySqlCommand.CommandText = "DELETE * FROM CashierMain WHERE RowID= @RowID";
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
mySqlDataAdapter.DeleteCommand = mySqlCommand;
.
conn.Open();
DataSet myDataSet = new DataSet();
mySqlDataAdapter.Fill(myDataSet, "CashierMain");
myDataSet.Tables["CashierMain"].Rows[e.Item.ItemIndex].Delete();
mySqlDataAdapter.Update(myDataSet, "CashierMain");
myDataSet.AcceptChanges();
GetCashierData(); //Rebind
Any ideas?
Thanks
MeonR
"The beatings will continue until morale improves
I am trying to get a webcontrols DataGrid(NET2.0) to update/delete. I have this code in the DeleteCommand event in the code behind and its throwing this exception:
System.IndexOutOfRangeException: An SqlParameter with ParameterName '@RowID' is not contained by this SqlParameterCollection.
SqlConnection conn = new SqlConnection(connString);
SqlCommand mySqlCommand = conn.CreateCommand();
mySqlCommand.Parameters["@RowID"].Value = DataGrid1.DataKeys[e.Item.ItemIndex]; //Throws //IndexOutOfRange exception
mySqlCommand.CommandText = "DELETE * FROM CashierMain WHERE RowID= @RowID";
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
mySqlDataAdapter.DeleteCommand = mySqlCommand;
.
conn.Open();
DataSet myDataSet = new DataSet();
mySqlDataAdapter.Fill(myDataSet, "CashierMain");
myDataSet.Tables["CashierMain"].Rows[e.Item.ItemIndex].Delete();
mySqlDataAdapter.Update(myDataSet, "CashierMain");
myDataSet.AcceptChanges();
GetCashierData(); //Rebind
Any ideas?
Thanks
MeonR
"The beatings will continue until morale improves