Solved

ADO.Net SqlDataAdapter Update Command for Typed Dataset not working

Posted on 2007-03-29
2
1,112 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now