Hello Everybody,
I am dealing with the following problem: I use a MSSQL Stored Procedure for displaying my data in a DataGridView. The Update and Insert Commands work, but there is one problem:
On inserting a new Row, the auto-numbered primary key isn't send back to my DataAdaptar. So the insertion is successfull in the database, but the PK is left blank in the DataGridView. I allready tried some codes like:
private void _rowUpdated(object sender, SqlRowUpdatedEventArgs e)
{
if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert)
{
cmd = conn.CreateCommand();
cmd.CommandText = "SELECT @@IDENTITY FROM " + e.Row.Table.TableName;
DataRow r = dt.Rows[dt.Rows.Count - 1];
r.ItemArray[0] = cmd.ExecuteScalar();
//r.SetModified(); --> err?
r.AcceptChanges();
}
}
on the DataAdapter, but nothing seems to work. All the SQL commands work fine.
When I refresh the data in the DataGridView, everyting is perfect. But the problem with this is, that the sort order and column width are adjusted. And that isn't what I want.
Can someone help me with this problem?
Looking forward for the solutions!
Thanks!