[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Dataset not updating

Posted on 2006-04-22
6
Medium Priority
?
536 Views
Last Modified: 2008-01-16
I'm having a real problem updating a dataset.  Here is the code below:

       Dim strsqlST = "SELECT * FROM SoldTemp;"
         Dim SoldstempDS1 As New DataSet()
         Dim OleDBDataAdapter5 As New OleDb.OleDbDataAdapter(strsqlST, objConnection)
         OleDBDataAdapter5.Fill(SoldstempDS1, "SoldTemp")

                Dim strsqlSQ = _
                    "SELECT * FROM(Solds) WHERE ((City) = 'Westland');"
         Dim OleDBDataAdapter4 As New OleDb.OleDbDataAdapter(strsqlSQ, objConnection)
         Dim SoldsDS1 As New DataSet()
         OleDBDataAdapter4.Fill(SoldsDS1, "Solds")
         Dim dr As DataRow
          Dim cb As New OleDbCommandBuilder()
          cb = New OleDbCommandBuilder(OleDBDataAdapter5)

                For Each dr In SoldsDS1.Tables(0).Rows
                    SoldstempDS1.Tables("SoldTemp").ImportRow(dr)
                Next
            OleDBDataAdapter5.Update(SoldstempDS1, "SoldTemp")
            SoldstempDS1.AcceptChanges()

As you can see, I've got a commandbuilder in there, but I'm not sure if its the syntax or something else.  For your reference, if I put MSGBOX(SoldsTempDS1.Tables(0).rows.Count), it gives me the correct number of added rows, but the updates never get posted.  

Any help would be greatly appreciated.  

Marc
0
Comment
Question by:Marc333
6 Comments
 
LVL 10

Expert Comment

by:bchoor
ID: 16516554
Do you have a PK defined for your SoldTemp table? Sometimes, commandbuilder messes up if there is no primary key

HTH
~BC
0
 
LVL 3

Author Comment

by:Marc333
ID: 16516559
The primary key is an autonumber in the mdb file.  
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 16516574
Hi Marc333;

Try moving this line in your code

     cb = New OleDbCommandBuilder(OleDBDataAdapter5)

To just after thins line of code

    Dim OleDBDataAdapter5 As New OleDb.OleDbDataAdapter(strsqlST, objConnection)

But before this line of code.

    OleDBDataAdapter5.Fill(SoldstempDS1, "SoldTemp")

Fernando
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Author Comment

by:Marc333
ID: 16516582
No change...
0
 
LVL 14

Accepted Solution

by:
amyhxu earned 2000 total points
ID: 16520014
Calling ImportRow preserves the existing DataRowState, along with other values in the row. The rows you import from SoldDS1 have the "Unchanged" RowState. You can use DataTable.NewRow to add them, so that the RowState will be "Added" and the DataAdapter knows that the rows need to be inserted to database.

                Dim newRow As DataRow
                For Each dr In SoldsDS1.Tables(0).Rows
                    newRow = SoldstempDS1.Tables("SoldTemp").NewRow()
                    newRow.ItemArray = dr.ItemArray.Clone()
                    SoldstempDS1.Tables("SoldTemp").Rows.Add(newRow)
                Next
0
 
LVL 3

Author Comment

by:Marc333
ID: 16592531
amyhxu,
Sorry for the slow response but I've been out of town for the last week.  I hope to test your code in the next few days and if it looks good I'll award points.  Thanks for posting.  
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

867 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