DonnaF Posted August 26, 2003 Posted August 26, 2003 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 & "')" Quote
kleptos Posted August 26, 2003 Posted August 26, 2003 Does it produce any errors? Quote ..::[ kleptos ]::..
DonnaF Posted August 26, 2003 Author Posted August 26, 2003 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 Quote
Datahighway Posted August 26, 2003 Posted August 26, 2003 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 Quote
LostProgrammer Posted August 26, 2003 Posted August 26, 2003 sometimes, i take out the catch clause and just let it crash. the server error usually gives a little more detail as to what the problem is. Quote
kleptos Posted August 26, 2003 Posted August 26, 2003 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. Quote ..::[ kleptos ]::..
*Gurus* Derek Stone Posted August 26, 2003 *Gurus* Posted August 26, 2003 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... Quote Posting Guidelines
DonnaF Posted August 26, 2003 Author Posted August 26, 2003 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. Quote
kleptos Posted August 26, 2003 Posted August 26, 2003 Password is an SQL keyword, but i use it in my SQL tables all the time. Just wrap it in []'s and you can use it with no problems. Quote ..::[ kleptos ]::..
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.