简体   繁体   中英

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"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM