I have a project that input data to MySQL via vb.net application.
But, when I want to input the data, I got an error like this :
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''',,'',,'',',)' at line 1
This is my code :
Private Sub Insertbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Insertbtn.Click
Dim Query As String
'Query = "INSERT INTO userreg"
Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=test;User ID=root;Password=;")
'Dim sql As MySqlCommand = New MySqlCommand(Query, con)
Query = "INSERT INTO tbl_data_pegawai(nip, nama_pegawai, tempat_lahir, tanggal_lahir, jenis_kelamin, usia, status_pegawai, tanggal_pengangkatan_cpns, alamat)VALUES("
Query = Query + TextBox1.Text + ",'" + TextBox2.Text + "'," + TextBox3.Text + ",'" + TextBox4.Text + "'," + TextBox5.Text + TextBox6.Text + ",'" + TextBox7.Text + "'," + TextBox8.Text + "'," + TextBox9.Text + ")"
con.Open()
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
Dim i As Integer = cmd.ExecuteNonQuery()
If i > 0 Then
lblMsg.Text = "Success"
Else
lblMsg.Text = "Not Success"
End If
con.Close()
End Sub