472,139 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 software developers and data experts.

Syntax error in INSERT INTO statement.

2
I got the following error:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.

The source error is : MYcmd.ExecuteNonQuery()

Here is my Code: (Help me.....Thanks)
'========================================
Function addTeacherRecord(ByVal lName As String, ByVal fName As String)




' Change Data Source to the location of Northwind.mdb on your local
Dim sConStr As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data " _
& "Source=" & Server.MapPath("~/App_Data/students.mdb")


Dim password As String = generatePassword()
Dim userStatus As String

If statusList.SelectedIndex = 0 Then
userStatus = "Yes"
Else
userStatus = "No"
End If

Dim userProfile As String

If profileList.SelectedIndex = 0 Then
userProfile = "User"
Else
userProfile = "Admin"
End If

Dim user_name = fName + lName(0)



Dim mySQL As String = "INSERT INTO teachersTable (FirstName, LastName, UserName, Password, UserStatus,active) VALUES ('" & fName & "','" & lName & "','" & user_name & "','" & password & "','" & userProfile & "','" & 1 & "')"


Dim MyConn As New Data.OleDb.OleDbConnection(sConStr)


MyConn.Open()
Dim MYcmd As New Data.OleDb.OleDbCommand(mySQL, MyConn)
MYcmd.ExecuteNonQuery()
MyConn.Close()


newsLable1.Visible = True
newsLable2.Visible = True
newsLable2.Text = "הזנת הנתונים עבור " & fName & " " & lName & " הסתיימה בהצלחה."
userPassword1.Visible = True
userPassword1.Visible = True
userPassword1.Text = password
UserName2.Text = fName + lName(0)


Return 0
End Function
Mar 19 '07 #1
2 3121
clain
79
Dear..

this is a simple error...

Dim mySQL As String = "INSERT INTO teachersTable (FirstName, LastName, UserName, Password, UserStatus,active) VALUES ('" & fName & "','" & lName & "','" & user_name & "','" & password & "','" & userProfile & "','" & 1 & "')"

here is where you went wrong ..

you can change it to

Dim mySQL As String = "INSERT INTO teachersTable (FirstName, LastName, UserName, Password, UserStatus,active) VALUES ('" & fName & "','" & lName & "','" & user_name & "','" & password & "','" & userProfile & "',1)"

happy coding
Mar 20 '07 #2
abedt
2
Thanks for the help

I a new error, it's:
Expected query name after EXECUTE
Mar 20 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Gérard Leclercq | last post: by
2 posts views Thread by eric dugal | last post: by
3 posts views Thread by Neil Zanella | last post: by
3 posts views Thread by Nathan Sokalski | last post: by
5 posts views Thread by amitbadgi | last post: by
6 posts views Thread by ewpatton | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.