ccravenbartle
asked on
ADO.Net SqlDataAdapter Update Command for Typed Dataset not working
The table SecureNumbers contains a single row that holds fields storing the values for the next invoice number, next order number etc in an application. I am using a typed dataset generated from a SQLDataAdapter MRMSecureNumbers to read and update the SecureNumbers table.
The problem is that, when I run the following code, the function increments correctly and returns the next invoice number but does not save the incremented invoice number back to the table.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
Dim ConnectionString As String = My.Settings.EnterpriseMRMC onnectionS tring
Dim conn As New SqlConnection(ConnectionSt ring)
conn.Open()
Dim TDS As MRMSecureNumbers = New MRMSecureNumbers
Dim daSecureNumbers As SqlDataAdapter
daSecureNumbers = New SqlDataAdapter("SELECT * FROM SecureNumbers "
, conn)
daSecureNumbers.Fill(TDS, "SecureNumbers")
Dim tdsRow As MRMSecureNumbers.SecureNum bersRow
Dim cmd As New SqlCommandBuilder(daSecure Numbers)
daSecureNumbers.UpdateComm and = cmd.GetUpdateCommand
tdsRow = TDS.SecureNumbers.Rows(0)
With tdsRow
.BeginEdit()
.Invoice += 1
.EndEdit()
End With
TDS.AcceptChanges()
daSecureNumbers.Update(TDS , "SecureNumbers")
conn.Close()
Return tdsRow.Invoice
The problem is that, when I run the following code, the function increments correctly and returns the next invoice number but does not save the incremented invoice number back to the table.
--------------------------
Dim ConnectionString As String = My.Settings.EnterpriseMRMC
Dim conn As New SqlConnection(ConnectionSt
conn.Open()
Dim TDS As MRMSecureNumbers = New MRMSecureNumbers
Dim daSecureNumbers As SqlDataAdapter
daSecureNumbers = New SqlDataAdapter("SELECT * FROM SecureNumbers "
, conn)
daSecureNumbers.Fill(TDS, "SecureNumbers")
Dim tdsRow As MRMSecureNumbers.SecureNum
Dim cmd As New SqlCommandBuilder(daSecure
daSecureNumbers.UpdateComm
tdsRow = TDS.SecureNumbers.Rows(0)
With tdsRow
.BeginEdit()
.Invoice += 1
.EndEdit()
End With
TDS.AcceptChanges()
daSecureNumbers.Update(TDS
conn.Close()
Return tdsRow.Invoice
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER