A1VBCode Forums

Insert Statment Error


http://a1vbcode.com/vbforums/Topic29059.aspx

By zulli-mlt - 3/25/2010

[

Dim con As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\Users .... ") 'This here, declares where the database is located



Dim dt As New DataTable()

Dim str As String

Dim com As OleDb.OleDbCommand



Dim user_name As String = txtusername.Text

Dim pass_word As String = txtpassword.Text

'Dim application As String = txtapplication.Text



'try statement

Try

'declaration stage, declare all database components and strings



con.Open()



str = "insert into password(pass,username) values('" & pass_word & "','" & user_name & "')"



lblInfo.Text = "saved"



com = New Data.OleDb.OleDbCommand(str, con)

'execute the query

com.ExecuteNonQuery()

'close the connection

con.Close()



'if there is an error during the process ...

Catch ex As Exception

'warn the user that username is already taken

lblInfo.Text = "Username already exits. Please Try Another Username."



End Try

End Sub

/]





hi all, above is my code which is giving me some problems. actually im trying to insert into a MS ACCESS database, but for some reason im getting an error; Syntax error in INSERT INTO statement.



the thing is, when i paste the SQL statement into an SQL query it executes without any problems.



any help please?



please note im a bigginer Smile



thanks

mark
By Keithuk - 3/26/2010

Welcome to A1vbcode zulli-mlt.

It won't sort your problem but it will make your code stand out more professional. Please use Mark's Syntax.zip when posting VB code in here. Wink