Hi,i have some error for some help
when i try to run this code below i got this error "Syntax error in UPDATE statement."
at .ExecuteNonQuery() and i try to solve it for an hours but i can't , Anyone please help me !!
and i use System.Data.Oledb ( sorry for my bad english )

                Dim sqledit As String

                sqledit = "UPDATE Employee" _
                        & " SET ID_Code='" & TextBox1.Text & "'," _
                        & "Em_Name='" & TextBox2.Text & "'," _
                        & "Address='" & TextBox3.Text & "'," _
                        & "Tel='" & TextBox4.Text & "'," _
                        & "Position='" & TextBox5.Text & "'" _
                        & " WHERE ID_Code='" & TextBox1.Text & "'"

                With comAdd
                    .CommandType = CommandType.Text
                    .CommandText = sqledit
                    .Connection = Conn
                    .ExecuteNonQuery()
                End With

Recommended Answers

All 4 Replies

Output the contents of sqledit and paste it here. It will be helpful if you post your table structure too.

In your debugger, copy the contents of sqledit and run the query manually from your database. This makes it easier to spot check queries because it eliminates the obscuring of issues through VB.NET boilerplate.

this is my sqledit output

"UPDATE Employee SET ID_Code='S0002',Em_Name='John',Address='New York',Tel='088-246-6614',Position='Employee' WHERE ID_Code='S0002'"

and my table structure

all of my column have data type is text and have 255 lengh

In your debugger, copy the contents of sqledit and run the query manually from your database. This makes it easier to spot check queries because it eliminates the obscuring of issues through VB.NET boilerplate

yeah, thank you for your suggestion

i try copy content of sqledit and past it in query and run , it work.

but i so confuse ,why it don't work in vb.net

this is my module that use for connection database

i call Sub DataConnect() in my form_load

Imports System.Data
Imports System.Data.OleDb
Module Module1
    Const database_file As String = ".\dogclub.mdb"
    Dim strconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & database_file

    Public Conn As New OleDbConnection

    Sub DataConnect()
        If Conn.State = ConnectionState.Open Then Conn.Close()
        Conn.ConnectionString = strconn
        Conn.Open()
    End Sub
End Module

i think may be it is becuase of this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.