Solved

ADO.Net SqlDataAdapter Update Command for Typed Dataset not working

Posted on 2007-03-29
2
1,150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

630 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