views:

15

answers:

0

Is there a way to set a SqlParameter's value with DataGridView, if data-bound?

For example:

SqlCommand selCmd = CreateCommand("SELECT * FROM table1");

SqlCommand updCmd = CreateCommand("UPDATE table1 Set column1 = @column1 WHERE id = @id");
updCmd.Parameters.Add(new SqlParameter("column1"), SqlDbTypes.Int));
updCmd.Parameters.Add(new SqlParameter("id", SqlDbTypes.Int));

SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = selCmd;
da.UpdateCommand = updCmd;

da.Fill(_dataTable);
dgv.DataSource = _dataTable;

Then somewhere later:

da.Update();

How can I make sure it's getting the right column1 value that was edited and the right id for the row for the da.Update(); to work, otherwise it complains that I have not provided the value.

Or if there's a better way, please advise.

Thanks!