Updating datatable
Hi
I am building a Windows application using VSNet 2003.
I am using a DataTable in a dataset and I am binding the fields to a datagrid and a text box.
When moving to another row the text box displays the field named description.
When I add a new record or update one I fire the sub with the update,delete or insert command with a button.
If the last control before the click is the textbox the changes in the textbox are not saved unless I move to another record or click in a datagrids cell first.The changes in the datagrid are saved fine.
What I have to do to be able to insert or update properly?
here is my ins command
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim insert_sqc As New SqlCommand
With insert_sqc
.CommandText = _
" INSERT INTO AccidentExtraBenefits_T(Description, AsfPoso, Rate, Asfalistro, PolicyID)" & _
" VALUES (@Description, @AsfPoso, @Rate, @Asfalistro, @PolicyID);" & _
" SELECT ID, Description, AsfPoso, Rate, Asfalistro, PolicyID" & _
" FROM AccidentExtraBenefits_T WHERE (ID = @@IDENTITY)"
.Connection = Conn
.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Description", System.Data.SqlDbType.VarChar, 50, "Description"))
.Parameters.Add(New System.Data.SqlClient.SqlParameter("@AsfPoso", System.Data.SqlDbType.Money, 8, "AsfPoso"))
.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Rate", System.Data.SqlDbType.Real, 4, "Rate"))
.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Asfalistro", System.Data.SqlDbType.Money, 8, "Asfalistro"))
.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PolicyID", System.Data.SqlDbType.Int, 4)).Value = PolicyID
End With
.........similar for update and delete commands and then.......
Dim DAPosaAsfalisis As New SqlDataAdapter
With DAPosaAsfalisis
.DeleteCommand = delete_sqc
.InsertCommand = insert_sqc
.UpdateCommand = update_sqc
End With
Try
DAPosaAsfalisis.Update(DSBase.Tables("AccidentExtr aBenefits"))
DAPosaAsfalisis.Dispose()
insert_sqc.Dispose()
update_sqc.Dispose()
delete_sqc.Dispose()
Catch
DAPosaAsfalisis.Dispose()
insert_sqc.Dispose()
update_sqc.Dispose()
delete_sqc.Dispose()
MsgBox(Err.Description, MsgBoxStyle.Critical)
End Try
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thank you in advance
Best regards
Nikos
|