Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an error in here.
Insert into syntax error pls help me its urgent

SQL
Dim msg As String
          msg = MsgBox("Filling Up Complete,Do you want to save It?", vbYesNo)
          If msg = vbYes Then
              cmdInsert.CommandText = "INSERT INTO login (PersonelName,Position,Username,Password,Repassword,PIN) VALUES (?,?,?,?,?,?)"
              cmdInsert.Parameters.AddWithValue("PersonelName", TextBoxX1.Text)
              cmdInsert.Parameters.AddWithValue("Position", TextBoxX2.Text)
              cmdInsert.Parameters.AddWithValue("Username", TextBoxX3.Text)
              cmdInsert.Parameters.AddWithValue("Password", TextBoxX4.Text)
              cmdInsert.Parameters.AddWithValue("Repassword", TextBoxX5.Text)
              cmdInsert.Parameters.AddWithValue("PIN", TextBoxX6.Text)
              MsgBox("Registration Complete")
              cmdInsert.CommandType = CommandType.Text
              cmdInsert.Connection = cnnOLEDB
              cmdInsert.ExecuteNonQuery()
              TextBoxX1.Text = ""
              TextBoxX2.Text = ""
              TextBoxX3.Text = ""
              TextBoxX4.Text = ""
              TextBoxX5.Text = ""
              TextBoxX6.Text = ""
          Else

          End If
Posted

1 solution

VB
cmdInsert.CommandText = "INSERT INTO login (PersonelName,Position,Username,Password,Repassword,PIN) VALUES (@PersonelName,@Position,@Username,@Password,@Repassword,@PIN)"
cmdInsert.Parameters.AddWithValue("@PersonelName", TextBoxX1.Text)
cmdInsert.Parameters.AddWithValue("@Position", TextBoxX2.Text)
cmdInsert.Parameters.AddWithValue("@Username", TextBoxX3.Text)
cmdInsert.Parameters.AddWithValue("@Password", TextBoxX4.Text)
cmdInsert.Parameters.AddWithValue("@Repassword", TextBoxX5.Text)
cmdInsert.Parameters.AddWithValue("@PIN", TextBoxX6.Text)


The ?'s are the actual names of the parameters, not the column names. You need to tell the parameters where they go, since the command doesn't know anything about the schema of your database.
 
Share this answer
 
Comments
Crixalis Paul 19-Jun-13 23:24pm    
Sir its still not working :(

Dim msg As String
msg = MsgBox("Filling Up Complete,Do you want to save It?", vbYesNo)
If msg = vbYes Then
cmdInsert.CommandText = "INSERT INTO login (PersonelName,Position,Username,Password,Repassword,PIN) VALUES (@PersonelName,@Position,@Username,@Password,@Repassword,@PIN)"
cmdInsert.Parameters.AddWithValue("@PersonelName", TextBoxX1.Text)
cmdInsert.Parameters.AddWithValue("@Position", TextBoxX2.Text)
cmdInsert.Parameters.AddWithValue("@Username", TextBoxX3.Text)
cmdInsert.Parameters.AddWithValue("@Password", TextBoxX4.Text)
cmdInsert.Parameters.AddWithValue("@Repassword", TextBoxX5.Text)
cmdInsert.Parameters.AddWithValue("@PIN", TextBoxX6.Text)
MsgBox("Registration Complete")
cmdInsert.CommandType = CommandType.Text
cmdInsert.Connection = cnnOLEDB
cmdInsert.ExecuteNonQuery()
TextBoxX1.Text = ""
TextBoxX2.Text = ""
TextBoxX3.Text = ""
TextBoxX4.Text = ""
TextBoxX5.Text = ""
TextBoxX6.Text = ""
Else

End If
Ron Beyer 19-Jun-13 23:42pm    
Please give more information about what "isn't working". Is it giving an error? Is it not inserting? We can't see your screen, or reproduce your database, or the rest of your code, you need to help us by giving as much information as you can, "its not working" doesn't help us solve the problem.
Crixalis Paul 20-Jun-13 0:10am    
These is my whole code and i will show you each of it with explanations.

I have an access database namely register and with a table named login.
In the login table these are my fields
-PersonelName
-Position
-Username
-Password
-PIN

then I save this as 2003 filr (register.mdb) in the desktop location

These is my 1st code that includes imports.
Imports System.DateTime
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms

My second code is all the declarations together with the Provider.
Dim cnnOLEDB As New OleDbConnection
Dim strConnectionString = "Provider=Microsoft.jet.oledb.4.0;data source=C:\Users\mypc\Desktop\register.mdb;"
Dim cmdInsert As New OleDbCommand
Dim cmdupodate As New OleDbCommand

I put this on the public class form.

Then I put the code below on the form load

cnnOLEDB.ConnectionString = strConnectionString
cnnOLEDB.Open()

then lastly this is my code on insert that need to pass all the validations before inserting.

If TextBoxX1.Text = "" And TextBoxX2.Text = "" And TextBoxX3.Text = "" And TextBoxX4.Text = "" And TextBoxX5.Text = "" And TextBoxX6.Text = "" Then
MsgBox("Please fill out all the Information.")
ElseIf TextBoxX1.Text = "" Then
MsgBox("Please provide your name.")
ElseIf TextBoxX2.Text = "" Then
MsgBox("Whats your position in the company?")
ElseIf TextBoxX3.Text = "" Then
MsgBox("Please provide us your Username.")
ElseIf TextBoxX4.Text = "" Then
MsgBox("Please provide your Password.")
ElseIf TextBoxX5.Text = "" Then
MsgBox("Please Re-Type your Password.")
ElseIf TextBoxX6.Text = "" Then
MsgBox("Create your Own Personal Identification Number")
ElseIf Not (TextBoxX4.Text = TextBoxX5.Text) Then
MsgBox("Password and Repeat Password are not Equal.")
Else
Dim msg As String
msg = MsgBox("Filling Up Complete,Do you want to save It?", vbYesNo)
If msg = vbYes Then
cmdInsert.CommandText = "INSERT INTO [login] (PersonelName,Position,Username,Password,Repassword,PIN) VALUES (@PersonelName,@Position,@Username,@Password,@Repassword,@PIN);"
cmdInsert.Parameters.AddWithValue("@PersonelName", TextBoxX1.Text)
cmdInsert.Parameters.AddWithValue("@Position", TextBoxX2.Text)
cmdInsert.Parameters.AddWithValue("@Username", TextBoxX3.Text)
cmdInsert.Parameters.AddWithValue("@Password", TextBoxX4.Text)
cmdInsert.Parameters.AddWithValue("@Repassword", TextBoxX5.Text)
cmdInsert.Parameters.AddWithValue("@PIN", TextBoxX6.Text)
MsgBox("Registration Complete")
cmdInsert.CommandType = CommandType.Text
cmdInsert.Connection = cnnOLEDB
cmdInsert.ExecuteNonQuery()
TextBoxX1.Text = ""
TextBoxX2.Text = ""
TextBoxX3.Text = ""
TextBoxX4.Text = ""
TextBoxX5.Text = ""
TextBoxX6.Text = ""
Else
End If
End If

Thats all I hope its. oK
-
Crixalis Paul 20-Jun-13 0:20am    
The error is (Sytax Error in Insert Statement
)
Ron Beyer 20-Jun-13 0:30am    
Your problem is this line:


cmdInsert.Parameters.AddWithValue("@PersonelName(", TextBoxX1.Text)

See the ( after personel name? Remove that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900