Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm getting a syntax error on an Insert statement, but I don't see anything wrong with it. It has the correct database names, and they are in the correct order. All of the fields are defined as text on the database. Does anyone see anything wrong with this?

 

Thanks, Donna

 

DataAdapter1.InsertCommand.CommandText = _

"INSERT INTO Customers(CustomerID, FirstName, " & _

"LastName, Address, City, State, Zip, " & _

"Password) " & _

"VALUES ('" & strCustID & "' , " & _

"'" & mFirstName & "' , " & _

"'" & mLastName & "' , " & _

"'" & mAddress & "' , " & _

"'" & mCity & "' , " & _

"'" & mState & "' , " & _

"'" & mZip & "' , " & _

"'" & mPassword & "')"

Posted

I have this code, that does the catch on the error. When the message box pops up, it says: Syntax Error in Insert/Into Statement. That's all it says.

 

Try

DataAdapter1.InsertCommand.ExecuteNonQuery()

frmNew.lblMessage.Text = "Customer Number " & _

strCustID & " Registered Successfully"

Catch exceptionparameter As Exception

MessageBox.Show(exceptionparameter.Message)

End Try

Posted

Hi DonnaF,

 

you must use Apostrophe for your Statement.

e.g

INSERT INTO People (Name, Age)

VALUES ('Bugs Bunny', 7).

I dont know the value of yours variables. (mFirstName and so on)

 

 

Regards Datahighway

Posted

DataAdapter1.InsertCommand.CommandText = "INSERT INTO Customers(CustomerID, FirstName, LastName, Address, City, State, Zip, Password) VALUES ('" & strCustID & "','" & mFirstName & "','" & mLastName & "','" & mAddress & "','" & mCity & "','" & mState & "','" & mZip & "','" & mPassword & "')"

Sorry for the long page formatting, but this seemed to work for me.

..::[ kleptos ]::..
  • *Gurus*
Posted
DataAdapter1.InsertCommand.CommandText = "INSERT INTO Customers (CustomerID, FirstName, LastName, Address, City, State, Zip, Password) VALUES (@CustomerID, @FirstName, @LastName, @Address, @City, @State, @Zip, @Password)"

DataAdapter1.InsertCommand.Parameters("@CustomerID").SqlDbType = SqlDbType.Int
DataAdapter1.InsertCommand.Parameters("@CustomerID").Value = mCustomerID

DataAdapter1.InsertCommand.Parameters("@FirstName").SqlDbType = SqlDbType.NVarChar
DataAdapter1.InsertCommand.Parameters("@FirstName").Size = 64
DataAdapter1.InsertCommand.Parameters("@FirstName").Value = mFirstName

' etc...

Posted

Does anyone know if password is a VB reserved word? When I looked at the Windows generated code for the Insert Command, I noticed it had password bracketed like there was something special about it.

 

Me.OleDbInsertCommand1.CommandText = "INSERT INTO Customers(Address, City, CustomerID, FirstName, LastName, [Password]," & _

" State, Zip) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"

 

Password is what I called the field in the database, but maybe I should have called it something else.

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...