C#数据库操作问题

来源:百度知道 编辑:UC知道 时间:2024/05/26 21:51:55
string name=this.textBox1.Text.Trim();
string password=this.textBox1.Text.Trim();

string user = "select name,password from username where name ='" + name + "'and password='" + password + "'";

DataTable table = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(user, sql);
adapter.Fill(table);
if (table.Rows.Count == 1)
{
Main m = new Main();
m.Show();
this.Hide(); ;
}

else
{
MessageBox.Show("登陆有误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Question);
}

这个为什么输入用户名就能进入.....错在哪里?? 怎么改
加了空格还是不行,而且二楼的,我复制过去 也不行....晕...

string name=this.textBox1.Text.Trim();
string password=this.textBox1.Text.Trim();

这里你取用了同一个文本框的值,那么在 用户名和密码一样的情况下,当然就可以登录了哦~~~

你吧 错误 贴出来看一下 ?
是只要输入 用户名 不用密码也能登陆ma ?

SqlDataAdapter adapter = new SqlDataAdapter(user, sql);
参数对吗?前面应该是sql语句后面是connection的对象

string user = "select name,password from username where name ='" + name + "' and password='" + password + "'";