我是VC#和ADO SQLITE的新手......
我正在尝试根据另一个中的值更改组合框的内容...
我的问题在这里:
SQLiteCommand cmd3 = new SQLiteCommand("select distinct(ACTION) from ACTION_LIST where CATEGORY='comboBox1.text'", conn2);
用什么来做这项工作?这里'comboBox1.text'看作句子而不是变量......
以下是代码:
private void Form1_Load(object sender, EventArgs e)
{
using (SQLiteConnection conn1 = new SQLiteConnection(@"Data Source = Data\MRIS_DB_MASTER"))
{
conn1.Open();
SQLiteCommand cmd2 = new SQLiteCommand("select distinct(CATEGORY) from ACTION_LIST", conn1);
SQLiteDataAdapter adapter1 = new SQLiteDataAdapter(cmd2);
DataTable tbl1 = new DataTable();
adapter1.Fill(tbl1);
comboBox1.DataSource = tbl1;
comboBox1.DisplayMember = "CATEGORY";
adapter1.Dispose();
cmd2.Dispose();
}
using (SQLiteConnection conn2 = new SQLiteConnection(@"Data Source = Data\MRIS_DB_MASTER"))
{
conn2.Open();
SQLiteCommand cmd3 = new SQLiteCommand("select distinct(ACTION) from ACTION_LIST where CATEGORY='comboBox1.text'", conn2);
SQLiteDataAdapter adapter2 = new SQLiteDataAdapter(cmd3);
DataTable tbl2 = new DataTable();
adapter2.Fill(tbl2);
comboBox2.DataSource = tbl2;
comboBox2.DisplayMember = "ACTION";
adapter2.Dispose();
cmd3.Dispose();
}
}
谢谢
问候
答案 0 :(得分:1)
使用System.Data.SQLite.SQLiteParameter
。试试吧。 (我可能有一些语法错误,因为我现在无法对此进行测试......但它应该类似)
从你的代码:
SQLiteCommand cmd3 = new SQLiteCommand("select distinct(ACTION) from ACTION_LIST where CATEGORY=@category", conn2);
cmd3.Parameters.Add(new SQLiteParameter("@category",comboBox1.Text));
答案 1 :(得分:0)
comboBox1.Text是组合框的标签,需要comboBox1.SelectedValue。你还需要做aaron所说的并添加一个参数。