【发布时间】:2018-10-17 09:16:15
【问题描述】:
当我的数据库脱机时,我没有遇到此错误。我刚刚使用 db4free.net 使我的数据库联机。
每次我登录时都会发生此错误。有人能指出什么问题吗?
private void btnLogIn_Click(object sender, EventArgs e)
{
string query = "select * from tbl_accounts where username='" + tbxUsername.Text + "' and password='" + tbxPassword.Text + "'";
MySqlCommand command = new MySqlCommand(query, connection);
MySqlDataAdapter da = new MySqlDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
try
{
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
if (dt.Rows.Count > 0)
{
employee_id = (dr["employee_id"].ToString().PadLeft(4, '0'));
fullname = (dr["account_firstname"] + " " + dr["account_lastname"]).ToString();
this.Invoke(new Action(() =>
{
connection.Open();
command.ExecuteNonQuery();
connection.Close();
this.Close();
th = new Thread(openNewForm);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}));
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
这是错误:
更新: 这是我的连接字符串:
MySqlConnection connection = new MySqlConnection("datasource=db4free.net;Convert Zero Datetime=True;SslMode=none");
【问题讨论】:
-
分享
employee_id的类型。 -
我强烈建议您不要在公共网站上发布您的数据库身份验证详细信息 ;-)
-
另外,您的代码容易受到 SQL 注入的影响 - 您应该使用参数而不是连接字符串。见stackoverflow.com/questions/14376473/…
-
@Sham 我的employee_id 类型是int(4) 主键auto_increment zerofill
-
有没有使用 GUID 的地方?