C# 登录代码 输入正确账户和密码却提示输入错误
“登录”按钮触发事件privatevoidbutton1_Click(objectsender,EventArgse){stringrole=cbRole.Text;if...
“登录”按钮触发事件
private void button1_Click(object sender, EventArgs e)
{
string role = cbRole.Text;
if (textBox1.Text == "")
{
MessageBox.Show("请输入用户名称");
}
else if (textBox2.Text == "")
{
MessageBox.Show("请输入用户密码");
}
else if (role == "")
{
MessageBox.Show("请选择用户角色");
}
else
{
myConnectionString = @"Server=(local)\SQL_2005;INTEGRATED SECURITY=TRUE;" +
"Database=平面设计";
SqlConnection thisConnection = new SqlConnection(myConnectionString);
string selectstr = "select 用户名称,用户密码 from 用户 ";
SqlCommand cmm= new SqlCommand(selectstr, thisConnection);
thisConnection.Open();
SqlDataReader myDataReader;
myDataReader = cmm.ExecuteReader();
bool b_accept = false;
while (myDataReader.Read())
{
if ((myDataReader.GetString(0).ToString()) == (textBox1.Text.ToString()))
{
if(( myDataReader.GetString(1).ToString()) == (textBox2.Text.ToString
()))
{
b_accept = true;
break;
}
}
}
if (b_accept == true)
{
this.Close();
MainForm f2 = new MainForm();
f2.Show();
}
else
{
MessageBox.Show("用户名或密码不正确,请重新输入!", "错误");
}
}
}
数据库:表——用户,有两列——用户名称,用户密码!!
有没有人帮忙看看!输入正确账户和密码却提示输入错误 展开
private void button1_Click(object sender, EventArgs e)
{
string role = cbRole.Text;
if (textBox1.Text == "")
{
MessageBox.Show("请输入用户名称");
}
else if (textBox2.Text == "")
{
MessageBox.Show("请输入用户密码");
}
else if (role == "")
{
MessageBox.Show("请选择用户角色");
}
else
{
myConnectionString = @"Server=(local)\SQL_2005;INTEGRATED SECURITY=TRUE;" +
"Database=平面设计";
SqlConnection thisConnection = new SqlConnection(myConnectionString);
string selectstr = "select 用户名称,用户密码 from 用户 ";
SqlCommand cmm= new SqlCommand(selectstr, thisConnection);
thisConnection.Open();
SqlDataReader myDataReader;
myDataReader = cmm.ExecuteReader();
bool b_accept = false;
while (myDataReader.Read())
{
if ((myDataReader.GetString(0).ToString()) == (textBox1.Text.ToString()))
{
if(( myDataReader.GetString(1).ToString()) == (textBox2.Text.ToString
()))
{
b_accept = true;
break;
}
}
}
if (b_accept == true)
{
this.Close();
MainForm f2 = new MainForm();
f2.Show();
}
else
{
MessageBox.Show("用户名或密码不正确,请重新输入!", "错误");
}
}
}
数据库:表——用户,有两列——用户名称,用户密码!!
有没有人帮忙看看!输入正确账户和密码却提示输入错误 展开
6个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询