我无法找到能够解答此特定情况的帖子。也许我真的很累。无论如何,我正在为WinForms进行登录验证。我有一个名为DBFunctions.cs的类,它保存数据库连接信息等。我坚持认为“C#中的赋值的左侧必须是变量,属性或索引器”错误。请在下面找到我当前的代码。提前谢谢。
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();
}
}
}
}
}
答案 0 :(得分:3)
很简单,你将=
(赋值运算符)与==
(比较运算符)混淆。
你的意思是进入
if (VerifyUser(tbxUsername.Text, tbxPassword.Text) == true)
(而不是= true
)
但实际上,将布尔值与常量布尔值进行比较是一项冗余操作。
你应该使用:
if (VerifyUser(tbxUsername.Text, tbxPassword.Text))
答案 1 :(得分:0)
我试图将一个对象转换为bool。我宣布bool类型的状态并返回bool所以,我需要将公共对象更改为public bool。代码如下:
<强>原始强>
Initials = alphabeticallyOrderedList
.Select((word, index) => new { Word = word, WordIndex = index })
.GroupBy(x => x.Word[0])
.ToDictionary(charGroup => charGroup.Key, charGroup => charGroup.First().WordIndex);
<强>校正的强>
{
"id": "aabbbccdd",
"name": "Object 1",
"metadata": {
"attributeA": "This is a text attribute",
"attributeB": {
"key1": "complex attribute",
"key2": "complex attribute 2",
},
"attributeC": 1234
}
},
{
"id": "eeffffggghh",
"name": "Object 2",
"metadata": {
"attributeA": "This is a text attribute with a different value",
"attributeD": "Another text attribute",
"attributeE": True
}
}