在登录窗体中!账号、口令要求与数据库里的对应。
正确进行登录,否则弹出提示窗口。
public string str1;
public string str2;
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
return;
int i = 0;
SqlConnection mycon = new SqlConnection("data source=20100320-1432\\SQLEXPRESS; database=xitong; integrated security=true");
mycon.Open();
{
if (radioButton1.Checked)
{
SqlCommand cmd = new SqlCommand("select id,mima from guanliyuan", mycon);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
if (textBox1.Text == dr.GetString(0) && textBox2.Text == dr.GetString(1))
{ i = 1; break; } }
if (radioButton2.Checked)
{
SqlCommand cmd = new SqlCommand("select tno,mima from teacher", mycon);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
if (textBox1.Text == dr.GetString(0) && textBox2.Text == dr.GetString(1))
{ i = 1; break; }
}
if (radioButton3.Checked)
{
SqlCommand cmd = new SqlCommand("select sno,mima from stu", mycon);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
if (textBox1.Text == dr.GetString(0) && textBox2.Text == dr.GetString(1))
{ i = 1; break; }
}
mycon.Close();
str2 = textBox1.Text;
}
if (i == 1)
{
Form2 f2 = new Form2();
f2.Show();
this.Hide();
}
}
else
MessageBox.Show("请重新输入!", "系统提示", MessageBoxButtons.OKCancel,
MessageBoxIcon.Asterisk);
为何运行结果是没任何的反应?
正确进行登录,否则弹出提示窗口。
public string str1;
public string str2;
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
return;
int i = 0;
SqlConnection mycon = new SqlConnection("data source=20100320-1432\\SQLEXPRESS; database=xitong; integrated security=true");
mycon.Open();
{
if (radioButton1.Checked)
{
SqlCommand cmd = new SqlCommand("select id,mima from guanliyuan", mycon);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
if (textBox1.Text == dr.GetString(0) && textBox2.Text == dr.GetString(1))
{ i = 1; break; } }
if (radioButton2.Checked)
{
SqlCommand cmd = new SqlCommand("select tno,mima from teacher", mycon);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
if (textBox1.Text == dr.GetString(0) && textBox2.Text == dr.GetString(1))
{ i = 1; break; }
}
if (radioButton3.Checked)
{
SqlCommand cmd = new SqlCommand("select sno,mima from stu", mycon);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
if (textBox1.Text == dr.GetString(0) && textBox2.Text == dr.GetString(1))
{ i = 1; break; }
}
mycon.Close();
str2 = textBox1.Text;
}
if (i == 1)
{
Form2 f2 = new Form2();
f2.Show();
this.Hide();
}
}
else
MessageBox.Show("请重新输入!", "系统提示", MessageBoxButtons.OKCancel,
MessageBoxIcon.Asterisk);
为何运行结果是没任何的反应?
button1.Click+=new EventHandler(button1_Click);登录可以直接把用户名密码之类的信息放到Sql中比较
if((textBox1.Text != "") && (textBox2.Text != "")&&(i == 0))没提示 也不弹出
{
string myConnectionString = "Initial Catalog=你的数据库名;Data Source=localhost;Integrated Security=SSPI;";
myConnection = new SqlConnection(myConnectionString);
cmd = new SqlCommand();
cmd.Connection = myConnection;
myConnection.Open();
string sql;
sql = "select user from dr where ID='" + textBox1.Text.Trim() + "' and Pass= '" + textBox2.Text.Trim() + "'";//两个textBox用来输入用户名和密码
cmd.CommandText = sql;
if (cmd.ExecuteScalar() != null)
{
main ma = new main();//用户合法则显示主界面
ma.Show();
textBox1.Text = "";
textBox2.Text = "";
myConnection.Close();
}
else
{
if (MessageBox.Show("注册吗?", "提问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{ register ee = new register();//弹出注册界面
ee.Show(); }
else
{
myConnection.Close();
this.Close();
} myConnection.Close();
}
}
后来用的showDialog,通过设置窗体状态来解决的。