3 Replies - 910 Views - Last Post: 20 August 2013 - 09:26 AM Rate Topic: -----

#1 armentatron  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-August 13

problem updating table

Posted 16 August 2013 - 09:59 PM

hi, i wrote a code for user with passwords, saving these in to a microsoft access database table 1, it works well, then in other form i am trying to save and update information in the same database but in table 2 and it shows me an error, ( Syntax error in INSERT INTO statement.

this is the code that is taking me some trouble.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        
    dbprovider = "provider = Microsoft.ACE.OLEDB.12.0;"
        dbsource = "data source = C:\Users\Armenta10-30\Documents\proyectos\historial y recetario\historial\historial\uspasconters.mdb"
        con.ConnectionString = dbprovider & dbsource
        con.Open()
        sql = "SELECT * FROM Tabla1"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "adressbook1")

        MsgBox("se abrio la base de datos")

        con.Close()

        maxrow = ds.Tables("adressbook1").Rows.Count

        'mensaje para confirmar guardar receta 

        mensaje = MessageBox.Show("DESEA GUARDAR LOS DATOS?", "CONFIRMAR", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        If mensaje = Windows.Forms.DialogResult.Yes Then

            Dim cb As New OleDb.OleDbCommandBuilder(da)
            Dim dsnewrow As DataRow

            dsnewrow = ds.Tables("adressbook1").NewRow()
            dsnewrow.Item(1) = TextBox4.Text
            dsnewrow.Item(2) = TextBox6.Text
            dsnewrow.Item(4) = TextBox7.Text
            dsnewrow.Item(5) = TextBox8.Text
            dsnewrow.Item(6) = TextBox5.Text
            dsnewrow.Item(7) = TextBox1.Text

            dsnewrow.Item(10) = DateTimePicker1

             ds.Tables("adressbook1").Rows.Add(dsnewrow)

           da.Update(ds, "adressbook1") --------> heres the error
            
            MsgBox("DATOS GUARDADOS EXITOSAMENTE", MsgBoxStyle.Information, "OK")

        End If

please if someone know where is the mistake, i did the same with the users and passwords table and it is working also i can add and delete users, but i dont know why is not working with the second table, i appreciate all the help, thank you

This post has been edited by andrewsw: 17 August 2013 - 02:50 AM
Reason for edit:: Please use CODE tags


Is This A Good Question/Topic? 0
  • +

Replies To: problem updating table

#2 Wrath_014  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 49
  • Joined: 19-July 13

Re: problem updating table

Posted 17 August 2013 - 08:35 AM

You need the SQLCommandBuilder...

    Dim cb As SqlCommandBuilder 



Then add this:
cb = New SqlCommandBuilder(da)

This post has been edited by andrewsw: 17 August 2013 - 08:56 AM
Reason for edit:: Removed unnecessary quote

Was This Post Helpful? 0
  • +
  • -

#3 armentatron  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-August 13

Re: problem updating table

Posted 18 August 2013 - 11:30 PM

hi wrath, thank you for help me, i wrote as same you told me, but not work, still the same problem,
Was This Post Helpful? 0
  • +
  • -

#4 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 966
  • Joined: 09-May 09

Re: problem updating table

Posted 20 August 2013 - 09:26 AM

Heres a reference
http://msdn.microsof...andbuilder.aspx

it should help

This post has been edited by deery5000: 20 August 2013 - 09:28 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1