Question Syntaxis Problem

Miich13

New member
Joined
Apr 14, 2011
Messages
3
Programming Experience
3-5
I get syntaxis error when I try to debug this piece of code:

VB.NET:
OleDbConnectionNew.Open()
                Dim cmd As New OleDb.OleDbCommand("INSERT INTO AccountDetails(AccountDetails.Username, AccountDetails.Surname, AccountDetails.Name, AccountDetails.Street, AccountDetails.Streetnumber, AccountDetails.ZIP code, AccountDetails.City, AccountDetails.Country, AccountDetails.Password, AccountDetails.Secret question, AccountDetails.Secret question answer, AccountDetails.Geactiveerd) VALUES(@Username,@Surname,@Name,@Street,@Streetnumber,@Zip code,@City,@Country,@Password,@Secret question,@Secret question answer,'False')", OleDbConnectionNew)
                cmd.Parameters.AddWithValue("@Username", txtUsername.Text)
                cmd.Parameters.AddWithValue("@Surname", txtSurname.Text)
                cmd.Parameters.AddWithValue("@Name", txtName.Text)
                cmd.Parameters.AddWithValue("@Street", txtStreet.Text)
                cmd.Parameters.AddWithValue("@Streetnumber", txtStreetNumber.Text)
                cmd.Parameters.AddWithValue("@Zip code", txtZipCode.Text)
                cmd.Parameters.AddWithValue("@City", txtCity.Text)
                cmd.Parameters.AddWithValue("@Country", cboCountry.SelectedItem.ToString)
                cmd.Parameters.AddWithValue("@Password", txtPassword.Text)
                cmd.Parameters.AddWithValue("@Secret question", cboSecretQuestion.SelectedItem.ToString)
                cmd.Parameters.AddWithValue("@Secret question answer", txtSecretQuestionAnswer.Text)
                cmd.ExecuteNonQuery()

Can anyone help me?

error : The instruction INSERT INTO has a syntaxiserror.

Grtzz
 
Look at your field names, and your parameter names. I am nearly 100% sure that parameter names cannot have spaces in them, and if your field names are genuinely called that, then you will need to find a method of encapsulating the names in quotes.
 
Hi, Thanks for the quick reply.

I did change my column names in the database so there aren't spaces anymore but I still get an error message

my code is now:

VB.NET:
 Dim cmd As New OleDb.OleDbCommand("INSERT INTO AccountDetails(Username,Surname,Name,Street,Streetnumber,ZIP_code,City,Country,Password,Secret_question,Secret_question_answer,Geactiveerd) VALUES(@Username,@Surname,@Name,@Street,@Streetnumber,@Zip_code,@City,@Country,@Password,@Secret_question,@Secret_question_answer,@Geactiveerd)", OleDbConnectionNew)
                cmd.Parameters.AddWithValue("@Username", txtUsername.Text)
                cmd.Parameters.AddWithValue("@Surname", txtSurname.Text)
                cmd.Parameters.AddWithValue("@Name", txtName.Text)
                cmd.Parameters.AddWithValue("@Street", txtStreet.Text)
                cmd.Parameters.AddWithValue("@Streetnumber", txtStreetNumber.Text)
                cmd.Parameters.AddWithValue("@Zip_code", txtZipCode.Text)
                cmd.Parameters.AddWithValue("@City", txtCity.Text)
                cmd.Parameters.AddWithValue("@Country", cboCountry.SelectedItem.ToString)
                cmd.Parameters.AddWithValue("@Password", txtPassword.Text)
                cmd.Parameters.AddWithValue("@Secret_question", cboSecretQuestion.SelectedItem.ToString)
                cmd.Parameters.AddWithValue("@Secret_question_answer", txtSecretQuestionAnswer.Text)
                cmd.Parameters.AddWithValue("@Geactiveerd", "False")
                cmd.ExecuteNonQuery()

I don't need to add my primaire key of my table to the parameters do I?

Grtzz
Miich
 
No, you dont add primary key.

What type of database are you using?
 
Back
Top