在登录窗体中!账号、口令要求与数据库里的对应。
正确进行登录,否则弹出提示窗口。
        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);
为何运行结果是没任何的反应?

解决方案 »

  1.   

    看看有没有对应的事件
    button1.Click+=new EventHandler(button1_Click);登录可以直接把用户名密码之类的信息放到Sql中比较
      

  2.   

    大括号有点乱 好像
    if((textBox1.Text != "") && (textBox2.Text != "")&&(i == 0))没提示 也不弹出
      

  3.   

     private void button1_Click(object sender, EventArgs e)
            {
                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();
                }
            }
      

  4.   

    先打个断点调试一下,看看是哪里的问题,我以前遇到过类似问题,老是自己主动释放掉资源
    后来用的showDialog,通过设置窗体状态来解决的。
      

  5.   

    SqlConnection mycon = new SqlConnection(@"data source=20100320-1432\SQLEXPRESS; database=xitong; integrated security=true");