怎么在C#做的登录界面连接mysql数据库并判断用户名和用户密码是否配对。要有代码的

有没有人在啊,想请教下,怎么在C#做的登录界面连接mysql数据库并判断用户名和用户密码是否配对。要有代码的
最新回答
萌兽

2024-06-23 00:15:55

SqlConnection conn = new SqlConnection(strcon);

DataSet dstable = new DataSet();
string sqlStrSelect = "select * from TUser where UserName='" + txtuser.Text.Trim() + "'";
try
{
SqlDataAdapter adapter = new SqlDataAdapter(sqlStrSelect, conn);
dstable = new DataSet();
adapter.Fill(dstable, "用户");
UserName = Convert.ToString(dstable.Tables["用户"].Rows[0]["Username"]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return ;
}
finally
{

conn.Close();
}
//判断用户是否存在
if (dstable.Tables["用户"].Rows.Count == 0)
{
MessageBox.Show("不存在该用户,请重新输入!");
txtuser.Focus();
return;
}