簡體   English   中英

如何從C#asp.net中的數據庫獲取復選框值

[英]How to get checkbox value from database in 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();

任何人都可以指出正確的方法嗎?

您正在閱讀器上尋找GetOrdinal(...)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM