如何在C#asp.net中从数据库中获取复选框值

时间:2015-05-27 12:54:16

标签: c# asp.net

这是我到目前为止所拥有的。

//Getting access value from the AccessTable

SqlCommand cmadAccess;
string strAccess;
strAccess = "select * from AccessTable where Email='" +
    EmailTextBox.Text.Trim() + "'";
cmadAccess = new SqlCommand(strAccess, conn);
SqlDataReader readAccess = cmadAccess.ExecuteReader();
if (readAccess.Read()) {
    //here I am trying to display data from the database to the checkbox but it does not work.
}

这是我尝试过的两个例子:

TechnitianCheckBox.Checked = Convert.ToBoolean(readAccess["ClientTechnitian"]);

TechnitianCheckBox.Checked = readAccess["ClientTechnitian"].ToString();

有人能指出正确的方法吗?

1 个答案:

答案 0 :(得分:0)

您正在寻找读者的GetOrdinal(...)

TechnitianCheckBox.Checked = readAccess.GetBoolean(readAccess.GetOrdinal("ClientTechnitian"));