hi

i trying to update some information with a picture to the database

but it display followin error message

"Syntax Error in Update Statement"

this is my code

plz any one can help me?
i'm a beginner learning VB.net

Try

            Dim fsreader As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
            Dim breader As New BinaryReader(fsreader)

            Dim imgbuffer(fsreader.Length) As Byte
            breader.Read(imgbuffer, 0, fsreader.Length)
            fsreader.Close()
            con1.Open()

            com1.CommandText = "UPDATE Employee set EId=@dtaEId,DNo=@dtaDNo,FName=@dtaFname,MName=@dtaMName,LName=@dtaLName,Address_Line1=@dtaAddress1,Address_Line2=@dtaAddress2,Address_Line3=@dtaAddress3,NIC=@dtaNIC,DOB=@dataDOB,Gender=@dtaGender,,Telephone=@datTele,E_mail=@dtaEmail,Emp_Photo=@dtaPhoto WHERE EId='" & Me.MaskedTextBox6.Text & "'"
            com1.Connection = con1

            com1.Parameters.AddWithValue("@dtaEId", ECODEMasked1.Text)
            com1.Parameters.AddWithValue("@dtaDNo", MaskedTextBox5.Text)
            com1.Parameters.AddWithValue("@dtaFname", TextBox3.Text)
            com1.Parameters.AddWithValue("@dtaMName", TextBox4.Text)
            com1.Parameters.AddWithValue("@dtaLName", TextBox5.Text)
            com1.Parameters.AddWithValue("@dtaAddress1", TextBox6.Text)
            com1.Parameters.AddWithValue("@dtaAddress2", TextBox7.Text)
            com1.Parameters.AddWithValue("@dtaAddress3", TextBox8.Text)
            com1.Parameters.AddWithValue("@dtaNIC", ENICMasked3.Text)
            com1.Parameters.AddWithValue("@dataDOB", DateTimePicker1.Value.Date)
            com1.Parameters.AddWithValue("@dtaGender", ComboBox3.SelectedItem)
            com1.Parameters.AddWithValue("@datTele", ETeleMasked2.Text)
            com1.Parameters.AddWithValue("@dtaEmail", TextBox10.Text)
            com1.Parameters.AddWithValue("@dtaPhoto", imgbuffer)
            com1.ExecuteNonQuery()
            con1.Close()
            com1.Dispose()

            If MessageBox.Show("Are You Sure", "Upadet", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then

                MsgBox("Succsessfully Updated", MsgBoxStyle.Information, "Employee")
            End If

        Catch ex As Exception
            MsgBox(ex.ToString())
        End Try

It might be the double comma at

@dtaGender,,Telephone

and since you are using parameters everywhere else why not change

WHERE EId='" & Me.MaskedTextBox6.Text & "'"

to

WHERE EId=@EId

hi

i changed Above correction Reverend Jim said but

i display a anothe error message

I have run into similar situations in the past with the same exact error message.

Wrapping all of my field names in square brackets [field name] is what ultimately fixed my problems with that particular message.

Did you do anything about the double comma that Rev Jim mentioned? It appears that you are naming all of your fields in the update statement but skipping that one.

Is it a typo? If so, remove one of the commas. If not, use the field name that is getting skipped and assign some kind of legit or default value to it.

This article has been dead for over six months. Start a new discussion instead.