0

So I'm trying to insert text from textbox and combobox controls into an SQLite database, but i am getting a syntax error

private void btnConfirm_Click(object sender, EventArgs e)
    { 
        int indexID = 0;
        string username = txtUsername.Text;
        string password = txtPassword.Text;
        string firstName = txtFirstName.Text;
        string lastName = txtLastName.Text;
        int age = cmbAge.SelectedIndex + 1;
        string country = cmbCountry.Text;
        string city = txtCity.Text;
        string address = txtAddress.Text;
        string breeds = txtBreeds.Text;
        string notes = "None";

        SQLiteConnection registerConnection = new SQLiteConnection("Data Source=|DataDirectory|/Resources/database.sqlite;Version=3;");
        registerConnection.Open();
        SQLiteCommand registerCommand = new SQLiteCommand("INSERT INTO users (indexID,username,password,firstname,lastname,age,country,city,address,tigerbreeds,notes)", registerConnection);
        registerCommand.Parameters.AddWithValue("indexID", indexID); //0 for now, but we're going to change this later.
        registerCommand.Parameters.AddWithValue("username", username);
        registerCommand.Parameters.AddWithValue("password", password);
        registerCommand.Parameters.AddWithValue("firstname", firstName);
        registerCommand.Parameters.AddWithValue("lastname", lastName);
        registerCommand.Parameters.AddWithValue("age", age);
        registerCommand.Parameters.AddWithValue("country", country);
        registerCommand.Parameters.AddWithValue("city", city);
        registerCommand.Parameters.AddWithValue("address", address);
        registerCommand.Parameters.AddWithValue("tigerbreeds", breeds);
        registerCommand.Parameters.AddWithValue("tigerbreeds", notes);
        registerCommand.ExecuteNonQuery();
    }

Does anybody have any idea how to fix this?

An unhandled exception of type 'System.Data.SQLite.SQLiteException' occurred in System.Data.SQLite.dll Additional information: SQL logic error or missing database near ")": syntax error

2 Answers 2

0

Try updating to this:

SQLiteCommand registerCommand = new SQLiteCommand("INSERT INTO users (indexID,username,password,firstname,lastname,age,country,city,address,tigerbreeds,notes) VALUES (@indexID, @username, @password, @firstname, @lastname, @age, @country, @city, @address, @tigerbreeds, @notes)", registerConnection);
registerCommand.Parameters.AddWithValue("@indexID", indexID); //0 for now, but we're going to change this later.
registerCommand.Parameters.AddWithValue("@username", username);
registerCommand.Parameters.AddWithValue("@password", password);
registerCommand.Parameters.AddWithValue("@firstname", firstName);
registerCommand.Parameters.AddWithValue("@lastname", lastName);
registerCommand.Parameters.AddWithValue("@age", age);
registerCommand.Parameters.AddWithValue("@country", country);
registerCommand.Parameters.AddWithValue("@city", city);
registerCommand.Parameters.AddWithValue("@address", address);
registerCommand.Parameters.AddWithValue("@tigerbreeds", breeds);
registerCommand.Parameters.AddWithValue("@notes", notes);
registerCommand.ExecuteNonQuery();
Sign up to request clarification or add additional context in comments.

Comments

0

You must construct a valid SQL query . Insert (columnName) Values (@paramName)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.