473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

inserting into MS access using ASP.NET/VB

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.ExecuteCommandTextE rrorHandling(Int32
hr) at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object&
executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior
behavior, Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(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:lin e 39

Line 30 contains: cmdInsert.ExecuteNonQuery()

Thank you for your time,
Nov 17 '05 #1
1 1969
hi,

the easiest way to spot your error would be to write you insert statement
out to screen
either using response.write or trace.write/warn.

then copy the statement and paste in directly into access, correct the
statement so it works and then make the
changes to you code.

probabally best to wrap the call to execute non query in a try block and
handle any error your self.

cheers

martin
"Kevin" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
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.ExecuteCommandTextE rrorHandling(Int32
hr) at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object&
executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior
behavior, Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(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:lin e 39

Line 30 contains: cmdInsert.ExecuteNonQuery()

Thank you for your time,
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sms1 | last post by:
My Participants table in Access 2002 contains about 1500 records. The Notes field is OLE. I want to use Insert Object to insert MS Word into the Notes field. It is easily done using: Insert...
3
by: James Alba | last post by:
Hey all, I am accessing an ms access database using .NET and C#. Like so, /* Create the database connection. */ connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data...
9
by: Zak Milas | last post by:
The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data. Is the error I get when it get dbCmd.ExecuteNonQuery();. I have 15 fields to insert,...
15
by: yzlin04 | last post by:
Hello, I'm new in vb.net. I have a problem in inserting a new row to a MS Access database table. There is no error message comes out when i run my program, but when i check my MS Access table,...
18
by: hotflash | last post by:
Hi Mark et All, I understand that you created a very professional document and a similar issue forum out there regarding to Inserting the checkbox value into MS Access using ASP however; I am so...
0
by: freeskier | last post by:
Hello, Sorry for the newb question; I've spent a good amount of time trying to figure this out. I am fairly new to the Postgre world. I am currently in the process of upsizing several MS Access...
6
by: ashes | last post by:
Hi, I am creating an ecommerce website using Microsoft Visual Studio, VB.Net and MS Access 2003. I am new to VB.Net When someone wants to register on the website, they fill out a form and the...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
2
by: hakkatil | last post by:
Hi to all, I have a page that inserts excel sheet to access database. I am using asp. What I want to do is to check the inserting record if it is in the database. Basicly checking the dublicate...
1
by: evenlater | last post by:
I have an Excel workbook that I'm programming from Access. The rows in the workbook vary in height. So let's say row 8 is taller than the rows above it. If I *manually* insert 2 new rows at the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.