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