Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

instert into MS access with asp.net/vb

Status
Not open for further replies.

9871

Programmer
Aug 13, 2002
3
US
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=&quot;vb&quot; AutoEventWireup=&quot;true&quot; Codebehind=&quot;RegisterForm.aspx.vb&quot; Inherits=&quot;WebApplication1.RegisterForm&quot;%>
<%@ import Namespace=&quot;System.data.oledb&quot; %>
<%@ import Namespace=&quot;System.data&quot; %>
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<title>RegisterForm</title>
<script language=&quot;vb&quot; runat=&quot;server&quot;>
Sub SubmitBtn_Click (Source As Object, ByVal E as EventArgs)

dim listError as string
dim connectionString as string
connectionString = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myProject\WebApplication1\UserDB1.mdb;&quot;
dim objConn = New OleDbConnection( connectionString )
dim objCommand
try
objConn.Open()
dim InsertSQL as string
Response.Write(&quot;Connection established! <br />&quot;)

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(&quot;Sex&quot;)
pwd=Password.text

'Create Insert statement
InsertSQL =&quot;insert into Users (Email, FirstName, LastName, ScreenName, Sex, Password) &quot;
InsertSQL = InsertSQL & &quot;values('&quot; & eml &&quot;', '&quot; & fname &&quot;', '&quot; & lname &&quot;', '&quot; & sname &&quot;','&quot; & sex & &quot;', '&quot; & pwd &&quot;');&quot;
' Create OleDbCommand object
dim cmdInsert as New OleDbCommand(InsertSQL, objConn)
cmdInsert.ExecuteNonQuery()

Response.Write(&quot;Data Recorded&quot;)

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,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top