Results 1 to 5 of 5

Thread: [2005] Data Problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    351

    Unhappy [2005] Data Problem

    Hi All,

    This is the code i am using to load data from an access database and the code used to update the database:

    vb Code:
    1. Public custDA As OleDb.OleDbDataAdapter
    2. Public CustDS As New DataSet
    3.  
    4.     Private Sub frmCustomersContainer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.  
    6.         custDA = New OleDb.OleDbDataAdapter("SELECT * FROM Customers ORDER By Customers.customer ASC", con)
    7.         custDA.Fill(CustDS)
    8.  
    9.         Dim custTbl As DataTable = CustDS.Tables(0)
    10.  
    11.         Me.dgvCustomers.DataSource = custTbl
    12.         Me.dgvCustomers.Columns(0).Visible = False
    13.         Me.dgvCustomers.Columns(1).Width = Me.dgvCustomers.Width - 15
    14.  
    15.     End Sub

    vb Code:
    1. Private Sub frmCustDetailsDetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.         Dim tbl As DataTable = frmCustomersContainer.CustDS.Tables(0)
    4.  
    5.         txtAddress.DataBindings.Add("Text", tbl, "Address")
    6.         txtPostcode.DataBindings.Add("Text", tbl, "PostCode")
    7.  
    8. End Sub
    9.  
    10. Private Sub frmCustDetailsDetails_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Leave
    11.  
    12.         If frmCustomersContainer.CustDS.HasChanges Then
    13.             frmCustomersContainer.CustDS.AcceptChanges()
    14.             frmCustomersContainer.custDA.Update(frmCustomersContainer.CustDS.Tables(0))
    15.         End If
    16.  
    17. End Sub

    When i change either txtaddress or txtpostcode the dataset is updated but not the database.

    What am i missing?

    TIA

    Rico

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Data Problem

    Get rid of this:
    vb.net Code:
    1. frmCustomersContainer.CustDS.AcceptChanges()
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    351

    Re: [2005] Data Problem

    Thanks JMcilhinney,

    but that gives an exception: "Update requires a valid UpdateCommand when passed DataRow collection with modified rows." on the line:
    vb Code:
    1. frmCustomersContainer.custDA.Update(frmCustomersContainer.CustDS.Tables(0))

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Data Problem

    It's not the fact that that line was removed that is causing the exception. That line was setting all the data in the DataSet to Unchanged so there was nothing to save. Now that there is something to save you're seeing a completely separate issue.

    See the fourth example here.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    351

    Re: [2005] Data Problem

    Excellent, thanks for all the info!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width