C# Left-Hand Side Of An Assignment Must Be a Variable, Property or Indexer

谁说胖子不能爱 提交于 2019-11-29 13:04:57

Nice easy one, you're confusing = (the assignment operator) with == (the comparison operator).

You would be meaning to enter

if (VerifyUser(tbxUsername.Text, tbxPassword.Text) == true)

(rather than = true)

But really, comparing a boolean value with a constant boolean value is a redundant operation.

You should just use:

if (VerifyUser(tbxUsername.Text, tbxPassword.Text))

I was trying to convert an object to bool. I declared status of type bool and returned a bool so, I needed to change public object to public bool. Code follows:

Original:

public object VerifyUser(string userId, string password)
    {
        DBFunctions dbInfo = new DBFunctions();
        bool status = false;
        string verifyUserQry = "SELECT * FROM Employee WHERE UserName = '" + userId + "' AND Password = '" + password + "'";
        DataTable dt = default(DataTable);
        dt = dbInfo.OpenDTConnection(verifyUserQry);
        if (dt.Rows.Count == 1)
        {
            status = true;
        }
        return status;
    }

Corrected

public bool VerifyUser(string userId, string password)
    {
        DBFunctions dbInfo = new DBFunctions();
        bool status = false;
        string verifyUserQry = "SELECT * FROM Employee WHERE UserName = '" + userId + "' AND Password = '" + password + "'";
        DataTable dt = default(DataTable);
        dt = dbInfo.OpenDTConnection(verifyUserQry);
        if (dt.Rows.Count == 1)
        {
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!