tags:

views:

56

answers:

2

Hi, I'm a newbie in VC# and ADO SQLITE...

I'm trying to change the content of a combobox according to the value present in another one...

My problem is here :

SQLiteCommand cmd3 = new SQLiteCommand("select distinct(ACTION) from ACTION_LIST where CATEGORY='comboBox1.text'", conn2);

What to use to do the job ? Here 'comboBox1.text' is see as a sentence not a variable...

Here is the code :

 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();
            }
        }

Thanks

regards

A: 

Use System.Data.SQLite.SQLiteParameter. Try this out. (I may have some syntax wrong because I'm not able to test this right now...but it should be similar)

From your code:

    SQLiteCommand cmd3 = new SQLiteCommand("select distinct(ACTION) from ACTION_LIST where CATEGORY=@category", conn2);
cmd3.Parameters.Add(new SQLiteParameter("@category",comboBox1.Text));
Aaron
Thanks, it's working like I want.Regards
nicodevil
A: 

comboBox1.Text is the label of the combobox, you need comboBox1.SelectedValue. You also need to do what aaron says and add a parameter.

Ben Robinson
Thanks, but it's really comboBox1.Text...
nicodevil
If you say so, but be aware that you are querying based on the label of the combobox not on the value the user has selected.
Ben Robinson