Your problems start with
string queryString = @"SELECT @SiteID, @Mount FROM AUDITOR_CHECKLIST " +
"WHERE SITE_ID = @SiteID";
I think this should be
string queryString = @"SELECT SITE_ID, MOUNT FROM AUDITOR_CHECKLIST " +
"WHERE SITE_ID = @SiteID";
i.e. return the columns from the database!
You haven't indicated how your "table of checkboxes" are related to this table - I'm guessing that SITE_ID would indicate which checkbox to update and that MOUNT is the 0/1 indicator
So your problems continue with ...
if (CheckBox1.Checked == true)
{
while (reader.Read())
{
cmd.Parameters.Add(new SqlParameter("@Mount", SqlDbType.Bit));
cmd.Parameters["@Mount"].Value = 1;
}
}
else
{
cmd.Parameters.Add(new SqlParameter("@Mount", SqlDbType.Bit));
cmd.Parameters["@Mount"].Value = 0;
}
Firstly, you're trying to add parameters to the sql after you have run it. and you're only running the query if CheckBox1 is
already checked. And you are not attempting to set the value of any checkbox.
I suspect that you really wanted something like (note I haven't tested this nor have I put in all of the proper try-catch, tests for null etc etc)
while (reader.Read())
{
int i = reader.GetOrdinal("SITE_ID");
int cbNum = reader.GetInt32(i);
CheckBox c = (CheckBox)this.Controls.Find("CheckBox" + cbNum.ToString(), True);
i = reader.GetOrdinal("MOUNT");
if(reader.GetByte(i) == 1)
c.Checked = reader.GetByte(i) == 1 ? true : false;
}
[EDIT - update in response to OP update of question]
Try replacing your sql with
SELECT Mount, Braker, Access, ConnNet, LogBook, Pictures, Floor, CbLenght, Channel FROM AUDITOR_CHECKLIST WHERE SITE_ID = @SiteID;
Note the only "@" symbol is for the SiteID
parameter
Then you can read the data using
while (reader.Read())
{
CheckBox1.Checked = Convert.ToBoolean(reader.GetByte(reader.GetOrdinal("Mount")))
CheckBox2.Checked = Convert.ToBoolean(reader.GetByte(reader.GetOrdinal("Braker")));
CheckBox3.Checked = Convert.ToBoolean(reader.GetByte(reader.GetOrdinal("Access")));
CheckBox4.Checked = Convert.ToBoolean(reader.GetByte(reader.GetOrdinal("ConnNet")));
CheckBox5.Checked = Convert.ToBoolean(reader.GetByte(reader.GetOrdinal("LogBook")));
CheckBox6.Checked = Convert.ToBoolean(reader.GetByte(reader.GetOrdinal("Pictures")));
CheckBox8.Checked = Convert.ToBoolean(reader.GetByte(reader.GetOrdinal("Floor")));
CheckBox9.Checked = Convert.ToBoolean(reader.GetByte(reader.GetOrdinal("Cblenght")));
CheckBox10.Checked = Convert.ToBoolean(reader.GetByte(reader.GetOrdinal("Channel")));
}
NB I've used the same spelling for
Cblenght
as you have - it might be Cblength on the database.