Kaittipol ThupmongKol Kaittipol ThupmongKol - 2 months ago 15
C# Question

System.Data.SqlClient.SqlException: 'Incorrect syntax near 'value'.'

I get an error all the time when I try to save an image and text into my SQL Server database.

Here is my code

If confirm("คุณต้องการจะเพิ่มข้อมูลหรือไม่") = vbNo Then Return

sql = "select count(*) from dataplantaev2 where loc = '" & txt_loc_save.Text & "'"
If cmd_excuteScalar() > 0 Then
error_message("ไม่สามารถเพิ่มได้ เนื่องจากมีอยู่แล้วในระบบ")
End If

sql = "insert into dataplantaev2 value(@loc, @sci, @fam, @type, @seri, @loca, @dom, @pic)"
cmd = New SqlClient.SqlCommand(sql, cn)
cmd.Parameters.AddWithValue("loc", txt_loc_save.Text)
cmd.Parameters.AddWithValue("sci", txt_sci_save.Text)
cmd.Parameters.AddWithValue("fam", txt_fam_save.Text)
cmd.Parameters.AddWithValue("type", txt_type_save.Text)
cmd.Parameters.AddWithValue("seri", txt_seri_save.Text)
cmd.Parameters.AddWithValue("loca", txt_loca_save.Text)
cmd.Parameters.AddWithValue("dom", txt_dom_save.Text)
cmd.Parameters.AddWithValue("pic", convert_PictureBox_toDatabase(PictureBox1))
If cmd.ExecuteNonQuery > 0 Then

End If

Answer Source

Let's try it again. Values not Value:

sql = "INSERT INTO dataplantaev2 VALUES(@loc, @sci, @fam, @type, @seri, @loca, @dom, @pic)"