Imports System.Data.OleDb

Public Class Form1
    Public con As New OleDbConnection
    Public cmd As New OleDbCommand
    Public da As New OleDbDataAdapter
    Public dr As OleDbDataReader

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim oOLE As String
        Try
            con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\BOND\BOND\bin\database\RBIBOND.mdb;Persist security info=False;"
        con.Open()
        oOLE = "Insert into UserMast(userid,username,password,rpassword) values (@userid,@username,@password,@rpassword)"
            cmd = New OleDbCommand(oOLE, con)

            cmd.Parameters.AddWithValue("@userid", TextBox1.Text)
        cmd.Parameters.AddWithValue("@username", TextBox2.Text)
        cmd.Parameters.AddWithValue("@password", TextBox3.Text)
        cmd.Parameters.AddWithValue("@rpassword", TextBox4.Text)

        cmd.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox("Data Saved Successfully")
        End Try
        con.Close()
    End Sub
End Class

Edited 5 Years Ago by Ezzaral: Fixed code tags.

"password" is a protected variable in SQL. Try this instead:

oOLE = "Insert into UserMast(userid,username,[password],rpassword) values (@userid,@username,@password,@rpassword)"

Conversion from string "System.Data.OleDb.OleDbException" to type 'Integer' is not valid.

change:
cmd.Parameters.AddWithValue("@userid", TextBox1.Text)
to:
cmd.Parameters.AddWithValue("@userid", CInt(TextBox1.Text))

oOLE = "Insert into UserMast(userid,username,password,rpassword) values (@userid,@username,@password,@rpassword)"

change

oOLE = "Insert into UserMast(userid,username,pass,rpass) values (@userid,@username,@password,@rpassword)"

oOLE = "Insert into UserMast(userid,username,password,rpassword) values (@userid,@username,@password,@rpassword)"

change

Don’t use field name more then eight character in MS ACCESS
oOLE = "Insert into UserMast(userid,username,pass,rpass) values (@userid,@username,@password,@rpassword)"

That’s why it displayed error message syntax error in INSERT INTO STATEMENT

Imports System.Data.OleDb
Public Class Form1
Public connStr As String
Public con As OleDbConnection
Public cmd As OleDbCommand
Public da As New OleDbDataAdapter
Public dr As OleDbDataReader

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sSQL As String
Try
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\BOND\BOND\DATABASE\BOND.mdb;Persist Security Info=False;"
con = New OleDbConnection(connStr)
con.Open()
sSQL = "INSERT INTO USER(USERID,USERNAME,[PASSWORD],RPASSWORD)VALUES(@USERID,@USERNAME,@PASSWORD,@RPASSWORD)"
cmd = New OleDbCommand(sSQL, con)
cmd.Parameters.AddWithValue("@USERID", CInt(TextBox1.Text))
cmd.Parameters.AddWithValue("@USERNAME", TextBox1.Text)
cmd.Parameters.AddWithValue("@PASSWORD", TextBox1.Text)
cmd.Parameters.AddWithValue("@RPASSWORD", TextBox1.Text)
cmd.ExecuteNonQuery()
MessageBox.Show("Data Saved Successfully")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Me.Close()
End Sub
End Class
CODE DISPLAY Syntax error in INSERT INTO statement, PLEASE GUIDE ME

This question has already been answered. Start a new discussion instead.