我想在我的應用程序中進行數據庫搜索,用戶將選擇列並輸入搜索詞,結果將出現在dataviewgrid中。 這是我一直在努力的代碼,問題是什麼都沒有出現,我很確定數據庫中有條目。編輯:這是一個Windows窗體應用程序在C中的SQL搜索查詢#
private void button1_Click(object sender, EventArgs e)
{
conn = new SqlConnection("Server = localhost; database = Clients; Integrated Security = SSPI");
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * From dbo.Tclients WHERE @choice = @input", conn);
cmd.Parameters.AddWithValue("@choice", comboBox1.Text);
cmd.Parameters.AddWithValue("@input", textBox1.Text);
ds = new DataSet();
da = new SqlDataAdapter(cmd);
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
conn.Close();
}
是否'Tclients'表包含'選擇'專欄?你要過濾哪一列? – 2014-09-13 18:31:37
您不能使用參數來表示列名或表名。 – Steve 2014-09-13 18:32:15
我不知道你不能這樣做,好吧。 – 2014-09-13 18:37:01