Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi guys,

 

I've been working with databases under the old ASP and Java (I'm familiar with SQL), and I've just started to play with VB .net not long ago.

 

I'm getting syntax errors where i shouldn't get any! This is the code:

 

Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FFFF_users.mdb;"

conn = New OleDbConnection(connString)
conn.Open()
command = New OleDbCommand("INSERT INTO users VALUES ('" & realName & "', '" & username & "', '" & password & "')", conn)

success = command.ExecuteNonQuery() = 1

 

The above works for an insertion, but if i change the INSERT statement to:

 

"INSERT INTO users (realName, username, password) VALUES ('" & realName & "', '" & username & "', '" & password & "')"

 

which specifies the columns explicitly, then i get a nice little exception:

 

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 FabulousFunForFree.userFunctions.registerSuccess(String realName, String username, String password)

 

I've tried just typing that INSERT command into an Access query, and it works. So i'm wondering if this is some issue with OleDb? I get a syntax error with UPDATE as well:

 

command = New OleDbCommand("UPDATE users SET password = '" & newPassword & "' WHERE username = '" & username & "'", conn)

 

this is truly weird :confused:

 

[edit]Please use

 tags [/ vb]...It is impossible to see Silver on a Grey background [/edit]
Edited by Robby
Posted

I think, SQL statement should look like this:

INSERT INTO users (realName, username, [password]) VALUES ('" & realName & "', '" & username & "', '" & password & "')"

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...