winform中登陆界面代码整了3个小时还不会啊。帮忙看看谢谢了
public partial class login : Form
{
static DataSet ds;
public login()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// if(ds.Tables[0].Rows[0][0].ToString()=="1231")
// textBox1.Text = "4565697897415646";
string str1 = textBox1.Text.ToString();
string str2 = textBox2.Text.ToString();
for(int i=0;i<ds.Tables["temp"].Rows.Count;i++)
if ((str1 == ds.Tables["temp"].Rows[i][0].ToString()) && (str2 == ds.Tables["temp"].Rows[i][1].ToString()))
{
//操作
break;
}
}
private void bindingSource1_CurrentChanged(object sender, EventArgs e)
{
}
private void login_Load(object sender, EventArgs e)
{
ds = new DataSet();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["毕设.Properties.Settings.bisheConnectionString"].ConnectionString);
conn.Open();
SqlDataAdapter sql = new SqlDataAdapter("select * from login", conn);
sql.Fill(ds, "temp");
}
------解决方案--------------------登录不就是验证用户名和密码。
------解决方案--------------------public partial class login : Form
{
static DataSet ds;
public login()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// if(ds.Tables[0].Rows[0][0].ToString()=="1231")
// textBox1.Text = "4565697897415646";
string str1 = textBox1.Text.ToString();
string str2 = textBox2.Text.ToString();
ds = new DataSet();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["毕设.Properties.Settings.bisheConnectionString"].ConnectionString);
string cmd=“select * from login where uid='+str1+' and pwd='+str2+' ”
conn.Open();
SqlDataAdapter sql = new SqlDataAdapter(cmd ,conn);
sql.Fill(ds, "temp");
// for(int i=0;i<ds.Tables["temp"].Rows.Count;i++)
if (ds.Tables["temp"].Rows.Count>0) {
//操作
}
ELSE
(RESPONSE.WRITE("请注册"))
}
}
------解决方案--------------------1,先判断输入账号,密码的正确性
2,用账号查询用户对象
3,再判断密码是否与查询的对象密码符合
4,如果符合就登录成功