Stan Sypek

Stan Sypek

  • NA
  • 18
  • 7.1k

Returning records to dataGridView using multiple checkboxes.

Nov 25 2014 1:12 PM
I am trying to pull records from a SQLite database based on checkboxes selected by the user.  Although the code shows no errors, both methods I have tried return an exception when run.  The code I have tried so far:

private void btnMedium_Click(object sender, EventArgs e)
   {
     readDataMedium();
   }
 

private void readDataMedium()
        {
            try
            {
                var datatable = new DataTable();
                myConnection.Open();
                string commandText = "Select * From Albums where Medium = '" + chk_CD.Checked.ToString() + "','" + chk_cassette.Checked.ToString() + "','" +
                chk_vinyl.Checked.ToString() + "','" + chk_vinyl.Checked.ToString() + "','" + chk_R2R.Checked.ToString() + "','" + chk_8Track.Checked.ToString() + "')";
                SQLiteDataAdapter mySqliteDataAdapter = new SQLiteDataAdapter(commandText, myConnection);
                mySqliteDataAdapter.Fill(datatable);
                myConnection.Close();
                dataGridView.DataSource = datatable;
            }

            catch (Exception)
            {
                throw;
            }
        }
 
I have also tried:
 
string commandText = "Select * From Albums where Medium = '" + chk_CD.Checked.Equals(true) + "','" + chk_cassette.Checked.Equals(true) + "','" + chk_vinyl.Checked.Equals(true) + "','" + chk_vinyl.Checked.Equals(true) + "','" + chk_R2R.Checked.Equals(true) + "','" + chk_8Track.Checked.Equals(true) + "')";
 
I would appreciate any help with this. Thanks in advance.
 
 

 

 
 

Answers (2)