Setting SqlParameter value automatically with DataGridView?
Posted
by johansson
on Stack Overflow
See other posts from Stack Overflow
or by johansson
Published on 2010-06-11T18:48:45Z
Indexed on
2010/06/11
18:52 UTC
Read the original article
Hit count: 220
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!
© Stack Overflow or respective owner