2017-02-26 8 views
0

だから私はSQLiteデータベースにテキストボックスとコンボボックスコントロールからテキストを挿入しようとしているが、私は誰もがどのようにこの問題を解決するために、任意のアイデアを持っています構文エラーC#のSQLiteのコマンドラインの構文エラー

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(); 
    } 

を取得しています?

型「System.Data.SQLite.SQLiteException」の未処理の例外がSystem.Data.SQLite.dll で発生しました追加情報

:SQLロジックエラーまたは欠落しているデータベース 近い「)」:構文エラー

答えて

0

てみてください

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(); 
0

有効なSQLクエリを作成する必要があります。 (columnName)値(@paramName)の挿入

関連する問題