0

i encounter an syntax error "Syntax Error in Insert Into" when i try to run this code... anyone can assist?

Dim sConnectionString As String
sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=H:\Users\Desktop\EmployeeAway2.xlsx;Extended Properties=""Excel 12.0;HDR=YES;"""
Dim objConn As New System.Data.OleDb.OleDbConnection(sConnectionString)
objConn.Open()
Dim objCmd As New System.Data.OleDb.OleDbCommand()
objCmd.Connection = objConn
objCmd.CommandText = "Insert into [Sheet1$] (EmployeeID, DateFiled, Name, Department, Reason, From, To, NumberofDays, LeaveApplied, ApprovedBy)" & _
" Values ('John', 'John', 'John', 'John', 'John', 'John', 'John', 'John', 'John', 'Thomas')"
objCmd.ExecuteNonQuery()
objConn.Close()
0

1 Answer 1

2

FROM and TO are reserved words, so you need to escape them like this : [FROM] and [TO].

Demo here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.