[英]How to get checkbox value from database in C# asp.net
Here is what I have so far. 这是我到目前为止所拥有的。
//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.
}
These are two examples of what I have tried: 这是我尝试过的两个示例:
TechnitianCheckBox.Checked = Convert.ToBoolean(readAccess["ClientTechnitian"]);
TechnitianCheckBox.Checked = readAccess["ClientTechnitian"].ToString();
Can anyone indicate the correct way to do this? 任何人都可以指出正确的方法吗?
您正在阅读器上寻找GetOrdinal(...)
。
TechnitianCheckBox.Checked = readAccess.GetBoolean(readAccess.GetOrdinal("ClientTechnitian"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.