INSERT INTO...(password) syntax error

J

jinhy82

Hi! I am currently creating a Registration form which contained: UserID
Password, FirstName and LastName.

These details would be inserted into Ms Access when I click submi
button. But I encounter with the problem to insert 'Password'. It work
fine if I did not insert 'Password' but if I did, it will shows that
have "syntax error: INSERT INTO..."

Did I miss something to write? Please kindly have a look on the cod
below, Thank you!

<%@ Import Namespace="System.Data" %>

<%@ Imports Namespace="System.Data.OleDb" %>

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e A
System.EventArgs) Handles btnSubmit.Click

Dim InsertCmd As New OleDbCommand

Dim SQLInsert As String

Dim DBConn As OleDbConnection

Dim Connstr As String

Connstr = "Provider=Microsoft.jet.oledb.4.0;" & _

"DAT
SOURCE=C:\Inetpub\wwwroot\samples\Project\bin\Project-Library.mdb"

SQLInsert = "INSERT INTO User_Profile (UserID, Password, FirstName
LastName) VALUES ('" & txtUserID.Text & "', '" & txtRegPwd.Text & "'
'" & txtFirstName.Text & "', '" & txtLastName.Text & "')"

'Create connection

DBConn = New OleDbConnection(Connstr)

InsertCmd.Connection = DBConn

InsertCmd.CommandText = SQLInsert

Try

DBConn.Open()

InsertCmd.ExecuteNonQuery()

Catch ex As Exception

Response.Write(ex.ToString())

Finally

DBConn.Close()

End Try

End Su
 
G

Guest

hi,
use [password] instead of password in the insert statement since password is
a reserved keyword.
 
H

Hans Kesting

jinhy82 said:
Hi! I am currently creating a Registration form which contained:
UserID, Password, FirstName and LastName.

These details would be inserted into Ms Access when I click submit
button. But I encounter with the problem to insert 'Password'. It
works fine if I did not insert 'Password' but if I did, it will
shows that I have "syntax error: INSERT INTO..."

Did I miss something to write? Please kindly have a look on the code
below, Thank you!

<%@ Import Namespace="System.Data" %>

<%@ Imports Namespace="System.Data.OleDb" %>

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click

Dim InsertCmd As New OleDbCommand

Dim SQLInsert As String

Dim DBConn As OleDbConnection

Dim Connstr As String

Connstr = "Provider=Microsoft.jet.oledb.4.0;" & _

"DATA
SOURCE=C:\Inetpub\wwwroot\samples\Project\bin\Project-Library.mdb"

SQLInsert = "INSERT INTO User_Profile (UserID, Password, FirstName,
LastName) VALUES ('" & txtUserID.Text & "', '" & txtRegPwd.Text & "',
'" & txtFirstName.Text & "', '" & txtLastName.Text & "')"

What if a mr O'Brian wants to register?? Your sql will crash!

Look up: sql injection attack
and start looking into parameters.

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top