小弟初学C#,做了一个登陆界面,输入了正确的密码但还是出错,下面是我的程序请高手帮忙看看,谢谢!string strConn = "Data source=LEE-03C9CC53F71\\SQLEXPRESS;Initial Catalog=Lee;User ID=sa;Password=lee";
DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");
DbConnection dbConn = dbProviderFactory.CreateConnection();
dbConn.ConnectionString = strConn;
dbConn.Open();
DbCommand dbComm = dbProviderFactory.CreateCommand();
dbComm.Connection = dbConn;
dbComm.CommandText = "select Id,Password from SystemAdministrator where Id='" + id + "'";//这里的id是从外面传入的
IDataReader reader = dbComm.ExecuteReader();
try
{
if (reader.Read())
{
if (reader.GetString(1) == strps)//就是这里,就算输入了正确的密码也通不过,我是从外面传入的一个字符串strps
{
SysAdministrator sa = new SysAdministrator();
sa.Show();
}
else
{
MessageBox.Show("密码错误");
}
}
else
{
MessageBox.Show("账号错误");
}
}
finally
{
reader.Close();
dbConn.Close();
dbConn.Dispose();
}
DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");
DbConnection dbConn = dbProviderFactory.CreateConnection();
dbConn.ConnectionString = strConn;
dbConn.Open();
DbCommand dbComm = dbProviderFactory.CreateCommand();
dbComm.Connection = dbConn;
dbComm.CommandText = "select Id,Password from SystemAdministrator where Id='" + id + "'";//这里的id是从外面传入的
IDataReader reader = dbComm.ExecuteReader();
try
{
if (reader.Read())
{
if (reader.GetString(1) == strps)//就是这里,就算输入了正确的密码也通不过,我是从外面传入的一个字符串strps
{
SysAdministrator sa = new SysAdministrator();
sa.Show();
}
else
{
MessageBox.Show("密码错误");
}
}
else
{
MessageBox.Show("账号错误");
}
}
finally
{
reader.Close();
dbConn.Close();
dbConn.Dispose();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货