简体   繁体   中英

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 (Convert.ToInt32(dt.ManagerColumn)>0)

Error:unable to cast object of type 'system.data.datacolumn' to type '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'

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".

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