Link to home
Start Free TrialLog in
Avatar of ccravenbartle
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.EnterpriseMRMConnectionString
Dim conn As New SqlConnection(ConnectionString)
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.SecureNumbersRow
Dim cmd As New SqlCommandBuilder(daSecureNumbers)
daSecureNumbers.UpdateCommand = 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

       
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ccravenbartle
ccravenbartle

ASKER

Excellent - worked a treat!