0

datagrid を使用して、sqlite に接続しています。sqlite の特定のテーブルをデータ グリッドで開くことができます。しかし今、テーブルから特定のものを検索したいのですが、select ステートメントを使用してテキスト ボックスを適用しています。ユーザーは入力を入力し、そこから検索します。以下は私のコードです

    private void button2_Click(object sender, EventArgs e)
    {
        SQLiteConnection connection2 = new SQLiteConnection(@"Data Source = C:\ssds\WEBATM\APTRABuilder.sqlite;Version =3");
        connection2.Open();
        string sql2 = "Select *from builderScreenResourceBundleTBL where screenId like '%_textboxSearch%'";
        SQLiteDataAdapter connect2 = new SQLiteDataAdapter(sql2, connection2);
        DataSet ds2 = new DataSet();
        connect2.Fill(ds2);
        dataGridView.DataSource = ds2.Tables[0];
    }

では、sql2 文字列ステートメントでは、テキスト ボックスからどのように入力する必要がありますか?

4

2 に答える 2

2

これをするだけ

string sql2 = 
"Select * from builderScreenResourceBundleTBL where screenId like '%"+YourTextBox.Text+"%'";
于 2012-11-20T09:45:26.257 に答える
0

上記のヨギの答えを使用するか、DataGridView にフィルターを直接適用できます。これは次のようになります。

private void textBox1_TextChanged(object sender, EventArgs e)
    {
        try
        {
            ((DataTable)dataGridView1.DataSource).DefaultView.RowFilter = string.Format("screenId like '%{0}%'", textBox1.Text.Trim().Replace("'", "''"));
        catch (Exception) { }

    }
于 2012-11-20T10:01:10.860 に答える