C# 方法不返回任何内容?
我对数据库检查登录详细信息的方法似乎没有返回任何信息。我看不出它有什么毛病。代码如下:C# 方法不返回任何内容?,c#,C#,我对数据库检查登录详细信息的方法似乎没有返回任何信息。我看不出它有什么毛病。代码如下: connection.Open(); if (chkRemember.Checked == true) { loginDetails(); } string command = @"SELECT email, password FROM zc_users WHERE email = '@user';"; t
connection.Open();
if (chkRemember.Checked == true)
{
loginDetails();
}
string command = @"SELECT email, password FROM zc_users WHERE email = '@user';";
try
{
// COMMAND DETAILS
MySqlCommand email = new MySqlCommand(command, connection);
// PARAMETERS
email.Parameters.AddWithValue("@user", txtEmail.Text);
// READER DETAILS
MySqlDataReader dr;
// CHECK DETAILS
dr = email.ExecuteReader();
if (dr.Read())
{
string passwordC = dr.GetString(1);
string saltedPass = Security.HashSalt.CreateHash(txtPassword.Text, passwordC);
bool match = IsPasswordMatch(passwordC, saltedPass);
if (match == true)
{
connection.Close();
string email2 = txtEmail.Text;
frmZilent frm = new frmZilent(email2);
frm.Show();
this.Hide();
}
else
{
msgEx m = new msgEx();
m.Show();
connection.Close();
}
}
connection.Close();
}
catch (MySqlException ex)
{
MessageBox.Show("Zilent Error: Code ZCx001. Please report this to the Zilent Team. Thanks. " + ex.Message);
connection.Close();
}
}
基本上,从数据库中选择电子邮件和密码,然后使用数据库中的密码对txtPassword
文本框中的密码进行哈希运算。该方法检查它们是否相同,如果相同,则关闭连接并显示下一个表单
我要么出错,要么什么也没发生。有什么想法吗?您的SQL在字符串文本中包含参数,因此该参数被解释为字符串文本,因此不会使用该值 你有:
SELECT email, password FROM zc_users WHERE email = '@user';
改为:
SELECT email, password FROM zc_users WHERE email = @user;
请注意,第二个版本中缺少撇号。
我要么得到一个错误
错误是什么<代码>什么都没有发生您是否尝试设置断点以查看代码失败的位置?方法没有返回任何内容
什么方法?@PoweredByOrange“调用Read()之前访问字段的尝试无效”,我尝试了并找到了它,但我在任何地方都看不到错误。用谷歌搜索错误,你会得到很多答案。我没有看到任何return
语句。您还将如何“返回”某些内容(尤其是因为您没有包含完整的函数)?