problem in insert instruction


Jun 9, 2004
Programming Experience
i have a table in MS Access 'users'
that table have these fields:
id (auto-increment)
login (text)
password (text)
type (number)

when i try to insert a new row into the table :

Dim sql As String
sql = "INSERT INTO users (login,password,type) VALUES ('" + Me.txt_name.Text + "','" + Me.txt_password.Text + "'," + Me.cmb_typo.SelectedValue + ")"

Dim connection As OleDbConnection = New OleDbConnection(Me.str_con)
Dim cmd As New OleDbCommand(sql, connection)
Dim num As Integer
cmd.CommandType = CommandType.Text
num = cmd.ExecuteNonQuery()
msgbox ("success")
Catch ex As Exception
End Try

it gives me an sintax error in the INSERT INTO instruction

if i try:
sql = "INSERT INTO users (login,password,typo) VALUES ('1','1',1)"
it gives me the same error.

can anyone help me?
Try this:
sql = "INSERT INTO [users] (login,password,type) VALUES ('" + Me.txt_name.Text + "','" + Me.txt_password.Text + "'," + Me.cmb_typo.SelectedValue + ")"

Also what's you may need to add the aspnet user to the permissions of the DB file.

If that doesn't fix it let me know what the error is.

it still gives me the same error.
i´m using to insert the values into the table using Microsoft Jet 4.0 Provider
the user has full access to the database and in the access he can add the rows...
the problem is, and i don't know why, in the sql statement
even when i try
sql = "INSERT INTO users (login,password,type) VALUES ('1','1',1)"
And you tried :
sql = "INSERT INTO [users] (login,password,type) VALUES ('1','1',1)"
TPM said:
And you tried :
sql = "INSERT INTO [users] (login,password,type) VALUES ('1','1',1)"

and also:
sql = "INSERT INTO users ('login','password','type') VALUES ('1','1',1)
sql = "INSERT INTO [users] ('login','password','type') VALUES ('1','1',1)
sql = "INSERT INTO users (login,password,type) VALUES ('1','1',1)

but at the end i made it:

sql = "INSERT INTO [users] ([login],[password],[type]) VALUES ('1','1',1)

i don't know why because in the select instruction i don't need so many [ ]...
Last edited:
Hmm strange indeed, like you say you shouldn't need the other []. It could be because your using Type as a field.