what am I missing in my update command? table wont update

G

Guest

Private Sub UpdateTblHistory()
Dim strSql As String

strSql = "Update tbl_History set SubscrID = @SubscrID Where ID = @ID"

da.UpdateCommand.CommandText = strSql
da.UpdateCommand.Parameters.Add("@SubscrID", SqlDbType.VarChar, 50,
"SubscrID")
da.UpdateCommand.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
da.Update(ds, "tbl_History")
End Su
----------------------------------------------------------------------------------

I am displaying a row from tbl_History in a datagridview. In the
datagridview_CellValueChanged event I call the update procedure above. The
code runs but tbl_History is not getting updated. Can anyone see why
tbl_History wont update?

Thanks,
Rich
 
G

Guest

Well, I added the following code to my update procedure. Now it updates, but
isnt' it supposed to be simpler than this?

---------------------------------------------------------
Private Sub UpdateTblHistory()
Dim strSql, str1 As String

For Each dr As DataRow In ds.Tables("tbl_History").Rows
If dr.RowState = DataRowState.Modified Then
str1 = dr("SubscrID").ToString
dr.BeginEdit()
dr("SubscrID") = str1
dr.EndEdit()
End If
Next

strSql = "Update tbl_History set SubscrID = @SubscrID Where ID = @ID"

da.UpdateCommand.CommandText = strSql
da.UpdateCommand.Parameters.Add("@SubscrID", SqlDbType.VarChar, 50,
"SubscrID")
da.UpdateCommand.Parameters.Add("@ID", SqlDbType.Int, 4, "ID")
da.Update(ds, "tbl_History")
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top