1

I have just started VB.net for several weeks. I want to make a form and Add data from textboxes and update a database (*.accdb) file. but the code I have written gives the following error:

Syntax error in UPDATE statement.

Private Sub Button1_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles Button1.Click
    ds6.Clear()
    cmd.Connection = con
    cmd.CommandText = "UPDATE Player SET pid='" + ComboBox3.Text + "', pfn='" _
        + TextBox2.Text + "',pmn='" + TextBox3.Text + "',pln='" + TextBox4.Text _
        + "',nic='" + TextBox5.Text + "',dob='" + DateTimePicker1.Value + "',telm='" _
        + MaskedTextBox1.Text + "',telh='" + MaskedTextBox2.Text + "',addr='" _
        + TextBox6.Text + "',email='" + TextBox10.Text + "',gndr='" + ComboBox1.Text _
        + "',weight='" + TextBox1.Text + "',hight'" + TextBox7.Text + "',sgrlvl'" _
        + TextBox11.Text + "',prate'" + TextBox8.Text + "' bloodg='" & ComboBox2.Text & "'"

    cmd.ExecuteNonQuery()
    MessageBox.Show("Player Updated")

    dssql6 = "select * from Player"
    da6 = New OleDb.OleDbDataAdapter(dssql6, con)
    da6.Fill(ds6, "Player")

    ComboBox1.Text = ("")
    ComboBox2.Text = ("")
    TextBox1.Text = ("")
    TextBox2.Clear()
    TextBox5.Clear()
    TextBox3.Clear()
    TextBox4.Clear()
    TextBox6.Clear()
    TextBox7.Clear()
    TextBox8.Clear()
    TextBox10.Clear()
    TextBox11.Clear()
    MaskedTextBox1.Clear()
    MaskedTextBox2.Clear()

End Sub

End Class

WillardSolutions
  • 2,316
  • 4
  • 28
  • 38
  • 6
    Learn to use parameters to avoid sql injection and formatting issues. – LarsTech Apr 29 '16 at 13:25
  • Are you updating all rows with the same information? You may be running into a key constraint if that is the case. There is no WHERE clause, are you inserting a new row? If so, you should use the INSERT command. You are missing equal signs as well. – interesting-name-here Apr 29 '16 at 13:28
  • `ds6`??? `da6`??? Does that mean you have *six* datasets and adapters? If so, stop and rethink the design. – Ňɏssa Pøngjǣrdenlarp Apr 29 '16 at 16:23

1 Answers1

3

You're missing equal signs for hight, sgrlvl and prate. Although LarsTech is right, you should do this using parameters.

Melanie
  • 3,021
  • 6
  • 38
  • 56