SQL 데이터베이스에 'True'및 'False'로 삽입되는 CheckBoxes 테이블이 있습니다. 그러나로드 이벤트를 사용하여 해당 값을 다시 검색하려고하지만이를 가져올 수 없습니다. 이건 내 코드입니다 :asp를 검색하는 방법 : SQL db에서 CheckBox 값을?
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();
}
}
덕분에 도움을 많이!
당신이 값을 검색하고 데시벨 값으로 컨트롤을 설정하거나 컨트롤을 저장하려고를 값을 데이터베이스에 저장 하시겠습니까? getAuditChecklist 메소드는 다른 f}으로 데이터베이스에서 상태 만 검색합니다. – angusf