Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Database and Reporting (http://www.xtremevbtalk.com/-net-database-and-reporting/)
-   -   Update database question (http://www.xtremevbtalk.com/-net-database-and-reporting/327716-update-database-question.html)

pjstreetglide 07-31-2015 04:52 AM

Update database question
 
Hi all, I'm new to the forum. I'm just learning to do database programing and I'm having a problem with updating my table in my database. the changes work fine in the dataset but does not show up in the database. Here is my code...
Code:

        With ItemCheckGrid
            ColSel = .CurrentCell.ColumnIndex
            RowDex = .CurrentCell.RowIndex
            Select Case True
                Case rbOrdered.Checked
                    .Rows(RowDex).Cells(ColSel).Value = "O"
                Case rbSched.Checked
                    .Rows(RowDex).Cells(ColSel).Value = "Sch"
                Case rbIP.Checked
                    .Rows(RowDex).Cells(ColSel).Value = "IP"
                Case rbDNA.Checked
                    .Rows(RowDex).Cells(ColSel).Value = "NA"
                Case rbClear.Checked
                    .Rows(RowDex).Cells(ColSel).Value = ""
                Case rbComplete.Checked
                    .Rows(RowDex).Cells(ColSel).Value = "x"
            End Select

            Try
                Dim cb As New OleDb.OleDbCommandBuilder(da)
                If ds.Tables("Trackerds").Rows(RowDex).Item(2) = FixedGrid.Rows(RowDex).Cells(1).Value Then

                    ds.Tables("Trackerds").Rows(RowDex).Item(1) = FixedGrid.Rows(RowDex).Cells(0).Value
                    ds.Tables("Trackerds").Rows(RowDex).Item(2) = FixedGrid.Rows(RowDex).Cells(1).Value
                    ds.Tables("Trackerds").Rows(RowDex).Item(3) = FixedGrid.Rows(RowDex).Cells(2).Value
                    ds.Tables("Trackerds").Rows(RowDex).Item(ColSel + 1) = .Rows(RowDex).Cells(ColSel).Value

                    ds.AcceptChanges()
                    da.Update(ds, "Trackerds")
                    MsgBox(ds.Tables("Trackerds").Rows(RowDex).Item(ColSel + 1))
                    MsgBox("Entry Saved")
                End If
            Catch exceptionObject As Exception
                MessageBox.Show(exceptionObject.Message)
            Finally

            End Try

        End With


pschulz 08-11-2015 05:19 PM

just by watching the code, might be possible, might be, that:
The last sql-statemant, given to the DataAdapter, its not the one which is needed at this point.
The commanduilder care about the last sql-statment, given to the DataAdapter.

PlausiblyDamp 08-11-2015 05:58 PM

Been a while since I have done anything with DataSets but IIRC the lines
Code:

ds.AcceptChanges()
da.Update(ds, "Trackerds")

Need to be swapped i.e. change them to
Code:

da.Update(ds, "Trackerds")
ds.AcceptChanges()

Calling .AcceptChanges on a DataSet marks all modified rows as being Unchanged, this means when you call .Update on the DataAdapter it doesn't see any changes to propagate to the database.


All times are GMT -6. The time now is 08:24 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.