Results 1 to 3 of 3

Thread: update database

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2011
    Location
    Sydney, Australia
    Posts
    756

    update database

    Hi All,
    I have a weird issue and no access to my past files to help me. I need to update the database, the code i have should work but it is telling me there is an error in my insert command. any ideas?

    Code:
     Dim con As New OleDb.OleDbConnection
            Dim dbProvider As String
            Dim dbSource As String
            Dim sql As String
            Dim ds As New DataSet
            Dim da As OleDb.OleDbDataAdapter
      
    
            dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
            dbSource = "Data Source = " & My.Settings.path & My.Settings.filename
    
            con.ConnectionString = dbProvider & dbSource
            con.Open()
    
            sql = "SELECT *  FROM customer"
            da = New OleDb.OleDbDataAdapter(sql, con)
            da.Fill(ds, "customer")
         
            con.Close()
            Dim cb As New OleDb.OleDbCommandBuilder(da)
    
            Dim dsNewRow As DataRow
            dsNewRow = ds.Tables("customer").NewRow()
    
            dsNewRow.Item("fname") = TextBox1.Text ' update recordds
            dsNewRow.Item("lname") = TextBox8.Text
            dsNewRow.Item("streetadd") = TextBox7.Text
            dsNewRow.Item("suburb") = TextBox6.Text
            dsNewRow.Item("postcode") = TextBox5.Text
            dsNewRow.Item("phone") = TextBox4.Text
            If TextBox3.Text = "" Then
                dsNewRow.Item("mobile") = "na"
            Else
                dsNewRow.Item("mobile") = TextBox3.Text ' if blank make "na"
            End If
            dsNewRow.Item("email") = TextBox2.Text
            Dim asd As Integer
            Dim dsa As String
            dsa = ComboBox5.Text
            asd = dsa
            dsNewRow.Item("max") = asd
            dsNewRow.Item("proptype") = ComboBox1.Text
            dsNewRow.Item("pertype") = ComboBox2.Text
            dsNewRow.Item("rooms") = ComboBox3.Text
            dsNewRow.Item("invesadd") = TextBox9.Text
            dsNewRow.Item("ivestsub") = TextBox10.Text
            dsNewRow.Item("investpost") = TextBox11.Text
    
    
            ds.Tables("customer").Rows.Add(dsNewRow)
    
            da.Update(ds, "customer")
    
            MsgBox("Data Updated")

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

    Re: update database

    The issue is most likely that you have one or more column names that are reserved words. The obvious culprit is "max". Either change them or else you must escape them to force them to be interpreted as identifiers. To do that, set the QuotePrefix and QuoteSuffix properties of your command builder to "[" and "]" respectively.
    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
    Fanatic Member
    Join Date
    Oct 2011
    Location
    Sydney, Australia
    Posts
    756

    Re: update database

    Thank you, I thought that may be the case but didnt think any were reserved.

    All working now thanx again

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