C#语句 在线等这解决string connStr = @"Data Source=.;Initial Catalog=zmgl;Integrated Security=True";//验证账户密码形式 //创建数据库连接对象 SqlConnection conn = new SqlConnection(connStr);

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/02 16:13:58
C#语句 在线等这解决string connStr = @

C#语句 在线等这解决string connStr = @"Data Source=.;Initial Catalog=zmgl;Integrated Security=True";//验证账户密码形式 //创建数据库连接对象 SqlConnection conn = new SqlConnection(connStr);
C#语句 在线等这解决
string connStr = @"Data Source=.;Initial Catalog=zmgl;Integrated Security=True";//验证账户密码形式
//创建数据库连接对象
SqlConnection conn = new SqlConnection(connStr);

//定义数据库查询语句
string sql = "select * from ma";
//创建执行sql语句的对象
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
//执行sql语句
DataSet ds = new DataSet();
sda.Fill(ds);


//显示数据
//this.dataGridView1.DataSource = ds.Tables[0];
//a = ds.Tables[0].Rows[0][0].ToString();
if (textBox1 .Text == ds.Tables[0].Rows[0][0].ToString ())
{
MessageBox.Show("密码正确!");
}
else
{
MessageBox.Show("密码错误!");
}
textBox1 .Text 的数据和ds.Tables[0].Rows[0][0].ToString ()数据是一致的 为什么提示 密码错误呢

C#语句 在线等这解决string connStr = @"Data Source=.;Initial Catalog=zmgl;Integrated Security=True";//验证账户密码形式 //创建数据库连接对象 SqlConnection conn = new SqlConnection(connStr);
textBox1 .Text 的数据和ds.Tables[0].Rows[0][0].ToString ()数据是一致的?可能是肉眼看是一致,但计算机就认为是不一致.
textBox1 .Text == ds.Tables[0].Rows[0][0].ToString ()改为:
textBox1 .Text.ToUpper() == ds.Tables[0].Rows[0][0].ToString ().ToUpper()
如果还不正确,再加.Trim()
再不正确,你调试一下.