简体   繁体   中英

How do I get the value of a boolean from a database field?

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = Lib.SqlConnection;
            MembersDataTable = new DataTable();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "SELECT MemberId, FirstName, Surname, Description as Grade, DateOfBirth, MedicalInformation , Paid, Permissions FROM Members m inner join Grade g on m.Grade = g.grade";
            cmd.CommandText += " WHERE MemberId = " + _MemberId;
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = cmd;
            adapter.Fill(MembersDataTable);FirstName.Text = MembersDataTable.Rows[0]["FirstName"].ToString();

            Surname.Text = MembersDataTable.Rows[0]["Surname"].ToString();
            GradeComboBox.Text = MembersDataTable.Rows[0]["Grade"].ToString();
            DOBPicker.Text = MembersDataTable.Rows[0]["DateOfBirth"].ToString().Replace("00:00:00", "");
            Medical.Text = MembersDataTable.Rows[0]["MedicalInformation"].ToString();

This is what I have so far, but I want to add in a checkbox called paid, which will get the value of paid from the main database and then if it is ticked in the main database then this new tickbox will be ticked will be ticked when this form is loaded.(Sorry if this is not clear, I don't know how better to explain it. If you need more information I can try to provide it)

使用三元运算符文档像这样设置您的复选框

PaidBox.Checked = (bool)MembersDataTable.Rows[0]["Paid"];

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