我连得是sql数据库 验证用户名密码是否正确 先在项目新建一个类 取名userinfo在类中定义:
public static string UserID;
public static string Password;
代码如下:
string sqlconn = "server = 220.162.131.160,1433;database = sqlwork;uid = sa;pwd = yxlbb520520";//数据库连接
string sqlqueryy = string.Format("select 账号,密码 from xs where 账号 = '{0}' and 密码 = '{1}'", textBox1.Text, textBox2.Text);
SqlConnection conn = new SqlConnection(sqlconn);
try
{
con.Open();
SqlCommand comm = new SqlCommand(sqlqueryy, con);
SqlDataReader ds = comm.ExecuteReader();
if (ds.Read())
{
userinfo1.UserID = ds[0].ToString();
userinfo1.Password = ds[1].ToString();
xs mf = new xs();
this.Hide();
mf.ShowDialog();
}
else
{
MessageBox.Show("用户名或密码错误!!!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
我连得是sql数据库
验证用户名密码是否正确
先在项目新建一个类
取名userinfo在类中定义:
public
static
string
UserID;
public
static
string
Password;
代码如下:
string
sqlconn
=
"server
=
220.162.131.160,1433;database
=
sqlwork;uid
=
sa;pwd
=
yxlbb520520";//数据库连接
string
sqlqueryy
=
string.Format("select
账号,密码
from
xs
where
账号
=
'{0}'
and
密码
=
'{1}'",
textBox1.Text,
textBox2.Text);
SqlConnection
conn
=
new
SqlConnection(sqlconn);
try
{
con.Open();
SqlCommand
comm
=
new
SqlCommand(sqlqueryy,
con);
SqlDataReader
ds
=
comm.ExecuteReader();
if
(ds.Read())
{
userinfo1.UserID
=
ds[0].ToString();
userinfo1.Password
=
ds[1].ToString();
xs
mf
=
new
xs();
this.Hide();
mf.ShowDialog();
}
else
{
MessageBox.Show("用户名或密码错误!!!");
}
}
catch
(Exception
ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}