[英]Reading a checkbox value from Access DB using C#
I'm working on a login form. 我正在使用登录表单。 Hoping that on the press of the Login button and reviewing the DB checking if the username and pw are correct to see whether a checkbox there is marked or no.
希望按下登录按钮并检查数据库,以检查用户名和密码是否正确,以查看是否选中了该复选框。
This's a part of the login button code! 这是登录按钮代码的一部分!
AppDataTableAdapters.MemberTableAdapter user = new AppDataTableAdapters.MemberTableAdapter();
AppData.MemberDataTable dt = user.GetDataByUsernamePassword(txtuser.Text, txtpw.Text);
if (dt.Rows.Count > 0)
{
if(Convert.ToInt32(dt.ManagerColumn)>0)
{
MessageBox.Show("Successfully logged in ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
//manager login process
}
else
{
MessageBox.Show("Successfully logged in", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
//Normal guest Login
}
}
I want that IF statement to go ahead and check the checkbox and proceed I've used different statements but I can only recall 2 errors rn 我希望该IF语句继续执行并选中该复选框并继续,我使用了不同的语句,但我只能记得2个错误rn
if (Convert.ToInt32(dt.ManagerColumn)>0)
Error:unable to cast object of type 'system.data.datacolumn' to type 'system.iconvertible' 错误:无法将类型为“ system.data.datacolumn”的对象转换为类型为“ system.iconvertible”的对象
if(dt.ManagerColumn == 1) - tying to see if it is true or no ^^
Error 1 Operator '==' cannot be applied to operands of type 'System.Data.DataColumn' and 'int' 错误1运算符'=='不能应用于类型'System.Data.DataColumn'和'int'的操作数
For ex. 对于前。
if(tbl.Rows.Count > 0)
{
foreach(DataRow row in tbl.Rows)
{
string fName = row[2].ToString(); // value in column 2 (zero-based).
string lName = row[3].ToString(); // value in column 3 (zero-based).
or: 要么:
string src = sources.Tables[0].Rows[i].Field<string>("Source").ToString();
// sources dataset;
// Table 0 in the dataset;
// Row i in the loop;
// value in the Field of type <string>, named "Source".
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.