c# - How to refresh record after an update with a SP -
I am facing the following problem: I used to store a MSSQL process to display my data in a DataGridView Please. On inserting a new row, the auto-numbered primary key is not sent back to my DataAdaptar: Enter the update and command is work, but there is a problem. Therefore the entry is successful in the database, but the PK datagrid is empty in the view. I tried some code like allready: Data works fine on all the SQL commands, but nothing seems to work on the adapter. When I refresh the data in DataGridView, everyting is perfect. But the problem with it is that sort order and column width are adjusted. Can anyone help me with this problem? Looking forward to the solution! Thank you!
Private Zero _rowUpdated (Object Sender, SqlRowUpdatedEventArgs e) {if (e.Status == UpdateStatus.Continue & amp; e.StatementType = = StatementType.Insert) {Cmd = conn.CreateCommand (); Cmd.CommandText = + e.Row.Table.TableName "Select the identity from @@"; Datarov R = DT. Ro [dt. Ro Number - 1]; R. Itamayr [0] = CMD. Excl. Sslar (); //r.SetModified (); - & gt; mistake? R.AcceptChanges (); }}
Finally got the answer and wanted to share it:
Dt.RowChanged + New Datourovision Handler (_update_fields); Private Zero _update_fields (Object Sender, DataRowChangeEventArgs e) {try (if.Action == DataRowAction.Add) {conn.Open (); Cmd = conn.CreateCommand (); Cmd.CommandText = "Select IDENT_CURRENT ('' + e.Row.Table.TableName + '')"; Dt.rows [dt.Rows.Count - 1] [0] = int.Parse (cmd.ExecuteScalar (.) ToString ()) + 1; Dt.AcceptChanges (); Conn.Close (); } Adapt.Update (dt); } Hold (SqlException pre) {Debug.WriteLine (ex.Message); } Hold (exception before) {Debug.WriteLine (ex.Message); }}
Hope this will save you some time! :)
GR VV
Comments
Post a Comment