Link to home
Start Free TrialLog in
Avatar of Marc333
Marc333

asked on

Dataset not updating

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
Avatar of bchoor
bchoor
Flag of United States of America image

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

HTH
~BC
Avatar of Marc333
Marc333

ASKER

The primary key is an autonumber in the mdb file.  
Avatar of Fernando Soto
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
Avatar of Marc333

ASKER

No change...
ASKER CERTIFIED SOLUTION
Avatar of amyhxu
amyhxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Marc333

ASKER

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.