Hello experts,
I'm a newbee to ASP.NET. And I have been struggling solving this problem. But I can't do it. Can you please help me get over this wall? Below is the code and error message:
<%@ Page Language="vb" AutoEventWireup="true" Codebehind="RegisterForm.aspx.vb" Inherits="WebApplication1.RegisterForm"%>
<%@ import Namespace="System.data.oledb" %>
<%@ import Namespace="System.data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>RegisterForm</title>
<script language="vb" runat="server">
Sub SubmitBtn_Click (Source As Object, ByVal E as EventArgs)
dim listError as string
dim connectionString as string
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myProject\WebApplication1\UserDB1.mdb;"
dim objConn = New OleDbConnection( connectionString )
dim objCommand
try
objConn.Open()
dim InsertSQL as string
Response.Write("Connection established! <br />"
dim fname as string
dim lname as string
dim sname as string
dim eml as string
dim pwd as string
dim sex as string
fname=FN.text
lname=LN.text
sname=ScreenName.text
eml=Email.text
sex=Request.Form("Sex"
pwd=Password.text
'Create Insert statement
InsertSQL ="insert into Users (Email, FirstName, LastName, ScreenName, Sex, Password) "
InsertSQL = InsertSQL & "values('" & eml &"', '" & fname &"', '" & lname &"', '" & sname &"','" & sex & "', '" & pwd &"');"
' Create OleDbCommand object
dim cmdInsert as New OleDbCommand(InsertSQL, objConn)
cmdInsert.ExecuteNonQuery()
Response.Write("Data Recorded"
catch Err as Exception
listError = Err.ToString()
Response.Write(listError)
end try
End Sub
</script>
ERROR:
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at ASP.RegisterForm_aspx.SubmitBtn_Click(Object Source, EventArgs E) in C:\myProject\WebApplication1\RegisterForm.aspx:line 39
Line 30 contains: cmdInsert.ExecuteNonQuery()
Thank you for your time,
I'm a newbee to ASP.NET. And I have been struggling solving this problem. But I can't do it. Can you please help me get over this wall? Below is the code and error message:
<%@ Page Language="vb" AutoEventWireup="true" Codebehind="RegisterForm.aspx.vb" Inherits="WebApplication1.RegisterForm"%>
<%@ import Namespace="System.data.oledb" %>
<%@ import Namespace="System.data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>RegisterForm</title>
<script language="vb" runat="server">
Sub SubmitBtn_Click (Source As Object, ByVal E as EventArgs)
dim listError as string
dim connectionString as string
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myProject\WebApplication1\UserDB1.mdb;"
dim objConn = New OleDbConnection( connectionString )
dim objCommand
try
objConn.Open()
dim InsertSQL as string
Response.Write("Connection established! <br />"
dim fname as string
dim lname as string
dim sname as string
dim eml as string
dim pwd as string
dim sex as string
fname=FN.text
lname=LN.text
sname=ScreenName.text
eml=Email.text
sex=Request.Form("Sex"
pwd=Password.text
'Create Insert statement
InsertSQL ="insert into Users (Email, FirstName, LastName, ScreenName, Sex, Password) "
InsertSQL = InsertSQL & "values('" & eml &"', '" & fname &"', '" & lname &"', '" & sname &"','" & sex & "', '" & pwd &"');"
' Create OleDbCommand object
dim cmdInsert as New OleDbCommand(InsertSQL, objConn)
cmdInsert.ExecuteNonQuery()
Response.Write("Data Recorded"
catch Err as Exception
listError = Err.ToString()
Response.Write(listError)
end try
End Sub
</script>
ERROR:
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at ASP.RegisterForm_aspx.SubmitBtn_Click(Object Source, EventArgs E) in C:\myProject\WebApplication1\RegisterForm.aspx:line 39
Line 30 contains: cmdInsert.ExecuteNonQuery()
Thank you for your time,