I am trying to simply insert a row into an Access Database. I can query data fine but inserting doesn't work. I get the following error:
-----------------------------------------------------
Syntax error in INSERT INTO statement.
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.
Source Error:
Line 15: cmdInsert.ExecuteNonQuery()
Stack Trace:
[OleDbException (0x80040e14): Syntax error in INSERT INTO statement.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +154
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +54
ASP.Register_aspx.btnInsert_OnClick(Object Sender, EventArgs E) in \\genfs3\ System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1263
-----------------------------------------------------
Below is my code:
-----------------------------------------------------
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import NameSpace="System.Data.OleDb" %>
<script language="VB" runat="server">
Sub btnInsert_OnClick(Sender As Object, E As EventArgs)
Dim myConnection As OleDbConnection
Dim cmdInsert as OleDbCommand
Dim strInsert as String
myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("database.mdb" & ";"
strInsert = "INSERT INTO USERS (USER_NAME, PASSWORD) VALUES ('bob', 'bobby')"
cmdInsert = New OleDbCommand(strInsert, myConnection)
myConnection.Open()
cmdInsert.ExecuteNonQuery()
myConnection.Close()
End Sub
</script>
-----------------------------------------------------
Any help with this would be GREATLY appreciated. I'm completely stuck here.
Thank you!
-Sean
-----------------------------------------------------
Syntax error in INSERT INTO statement.
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.
Source Error:
Line 15: cmdInsert.ExecuteNonQuery()
Stack Trace:
[OleDbException (0x80040e14): Syntax error in INSERT INTO statement.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +154
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +54
ASP.Register_aspx.btnInsert_OnClick(Object Sender, EventArgs E) in \\genfs3\ System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1263
-----------------------------------------------------
Below is my code:
-----------------------------------------------------
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import NameSpace="System.Data.OleDb" %>
<script language="VB" runat="server">
Sub btnInsert_OnClick(Sender As Object, E As EventArgs)
Dim myConnection As OleDbConnection
Dim cmdInsert as OleDbCommand
Dim strInsert as String
myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("database.mdb" & ";"
strInsert = "INSERT INTO USERS (USER_NAME, PASSWORD) VALUES ('bob', 'bobby')"
cmdInsert = New OleDbCommand(strInsert, myConnection)
myConnection.Open()
cmdInsert.ExecuteNonQuery()
myConnection.Close()
End Sub
</script>
-----------------------------------------------------
Any help with this would be GREATLY appreciated. I'm completely stuck here.
Thank you!
-Sean