Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
949 views
in Technique[技术] by (71.8m points)

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

I couldn't really find posts that answered this specific scenario. Plus maybe I am just really tired. Anyway, I am working on a login authentication for WinForms. I have a class named DBFunctions.cs which hold database connection info etc. I am stuck with this "The left-hand side of an assignment must be a variable, property or indexer" error in C#. Please find my current code below. Thanks in advance.

namespace emsdashboard
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();

}
//Contains the SQL string and other information to process
//user login.
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;
 }





   //When the login button is clicked. Check to see if the user
   //entered a username and/or password. Also verify the username
   //and the password are correct, else display an error message.
   private void btnLogin_Click(object sender, EventArgs e)
   {
   if(tbxUsername.Text=="" || tbxPassword.Text=="")
   {
   MessageBox.Show("Username and Password cannot be blank", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

    }
    else
    {
    if (VerifyUser(tbxUsername.Text, tbxPassword.Text) = true)
    {
    this.Hide();
    }
    }

    }
    }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...