I made some checkboxes outside of the datagrid viewer and I'm trying to associate a value of checked = true with the display of that information from the database. The database string variables have the same name as the checkbox names without the cbox at the end (i.e, X_Off_box associates with string X_Off) I've listed some of the code I have below. I used an array of the checkboxes to filter out all the true values. The button click is the function to display them.
public void CheckBoxLoop()
{
System.Windows.Forms.CheckBox[] boxes = new System.Windows.Forms.CheckBox[2];
boxes[0] = X_off_cbox;
boxes[1] = Y_off_cbox;
boxes[2] = Z_off_cbox;
for(int i=0; i<=2; i++)
{
if (boxes[i].Checked==true){
//return a variable for checkbox to associate with database?
}
}
}
private void show_btn_Click(object sender, EventArgs e)
{
//string constring = "";
SqlConnection con = new SqlConnection();
con.ConnectionString= @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Sample\Desktop\My Project\My Application\My_QA_App\My_QA_App\New_Data.mdf;Integrated Security=True;User Instance=True";
try
{
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from My_QA_Data", con);
System.Data.DataTable dt = new System.Data.DataTable();
sda.Fill(dt);
My_QA_DataDataGridView.DataSource = dt;
}
Aucun commentaire:
Enregistrer un commentaire