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

您可以使用上面 yogi 的答案,也可以直接在 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 回答