「True」と「False」として SQL データベースに挿入される CheckBoxes のテーブルがあります。しかし、load イベントでそれらの値を再度取得したいのですが、取得できません。これは私のコードです:
protected void Page_Load(object sender, EventArgs e)
{
if (auditChecklist != null)
{
//for loading audit checklist
getAuditChecklist();
}
}
以下の関数でそれらを取得しようとしましたが、それができると思いました:
private void getAuditChecklist()
{
//int i = 0;
SqlCommand cmd = null;
string conn = ConfigurationManager.ConnectionStrings["PSCV1ConnectionString"].ConnectionString;
string queryString = @"SELECT * FROM AUDIT_CHECKLIST " +
"WHERE SITE_ID = @SiteID";
using (SqlConnection connection =
new SqlConnection(conn))
{
SqlCommand command =
new SqlCommand(queryString, connection);
connection.Open();
cmd = new SqlCommand(queryString);
cmd.Connection = connection;
cmd.Parameters.Add(new SqlParameter("@SiteID", //the name of the parameter to map
System.Data.SqlDbType.NVarChar, //SqlDbType value
20, //The width of the parameter
"Site_ID")); //The name of the column source
//Fill the parameter with the value retrieved
//from the text field
cmd.Parameters["@SiteID"].Value = foo.Site_ID;
SqlDataReader reader = cmd.ExecuteReader();
if (CheckBox1.Checked == true)
{
while (reader.Read())
{
cmd.Parameters.Add(new SqlParameter("@Mount", //the name of the parameter to map
System.Data.SqlDbType.NVarChar, //SqlDbType value
20, //The width of the parameter
"Mount")); //The name of the column source
//Fill the parameter with the value retrieved
//from the text field
cmd.Parameters["@Mount"].Value = "True";
}
}
else
{
cmd.Parameters.Add(new SqlParameter("@Mount", //the name of the parameter to map
System.Data.SqlDbType.NVarChar, //SqlDbType value
20, //The width of the parameter
"Mount")); //The name of the column source
//Fill the parameter with the value retrieved
//from the text field
cmd.Parameters["@Mount"].Value = "False";
}
reader.Close();
}
}
助けてくれてありがとう!