日期:2014-05-17  浏览次数:21077 次

C#登陆界面求助,为什么我就是读不出数据出来!!

        private void button1_Click(object sender, EventArgs e)
        {
            String userid;

            String userpassword;

            userid = this.textBox1.Text;

            userpassword = this.textBox2.Text;

            if (userid == "" || userpassword == "")
            {

                MessageBox.Show("请确认您的输入!");

            }
            try
            {
                SqlConnection conn = new SqlConnection("server=.;database=Loading;Trusted_Connection=true");
                SqlCommand cmd = new SqlCommand("select count(*) from Loa where 用户名='" + userid + "'and 密码='" + userpassword + "'", conn);
                conn.Open();
                int count = Convert.ToInt32(cmd.ExecuteScalar().ToString());
                if (count>0)
                {
                    main form = new main();
                    form.MdiParent = this;
                    form.Show();
                    this.Hide();
                }