Solved

ADO.Net SqlDataAdapter Update Command for Typed Dataset not working

Posted on 2007-03-29
2
1,142 Views
Last Modified: 2009-09-08
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

       
0
Comment
Question by:ccravenbartle
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 18814448
These two lines are the wrong way round

TDS.AcceptChanges()
daSecureNumbers.Update(TDS, "SecureNumbers")

A dataadapter relies on the .RowState flags to know what has been altered and so needs updating.  .AcceptChanges cancels those flags.

Roger
0
 

Author Comment

by:ccravenbartle
ID: 18814548
Excellent - worked a treat!  
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question