mercredi 30 décembre 2015

How to Add Parameters in SQLite C#?

I'm using WPF and SQLite, I want to add new Parameters. I tried:

string _search;

private void txtSearchBox_TextChanged(object sender, TextChangedEventArgs e)
{
    _search = txtSearchBox.Text;
}

SQLiteConnection sqlite_conn = new SQLiteConnection("Data Source = music.db");
SQLiteCommand sqlite_cmd = new SQLiteCommand();

private void btn_search_Click(object sender, RoutedEventArgs e)
{
    sqlite_conn.Open();
    sqlite_cmd = sqlite_conn.CreateCommand();
    sqlite_cmd.CommandText = "select Title from Song where Title=@title";

    sqlite_cmd.Parameters.Add("@title",SqlDbType.NVarChar, -1);  // ************ //

    sqlite_cmd.Parameters["@title"].Value = _search;


    DataSet dataSet = new DataSet();
    SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(sqlite_cmd.CommandText,sqlite_conn);
    dataAdapter.Fill(dataSet);

    datagrid.ItemsSource = dataSet.Tables[0].DefaultView;
}

I got error on the line I ticked // ******* //. How can I fix it?

Aucun commentaire:

Enregistrer un commentaire