我在datagrid查看器之外做了一些复选框,我试图将checked = true的值与数据库中该信息的显示相关联。数据库字符串变量的名称与最后没有cbox的复选框名称相同(即,X_Off_box与字符串X_Off关联)我已经列出了下面的一些代码。我使用了一个复选框数组来过滤掉所有真值。按钮单击是显示它们的功能。
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;
}