Solved

ADO.Net SqlDataAdapter Update Command for Typed Dataset not working

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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