首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2013-08-01 
C#登陆界面求助,为什么我就是读不出数据出来!!private void button1_Click(object sender, EventArgs e){S

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();
                }


                conn.Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show("错误" + ex.ToString(), "错误");
            }

        }

[解决办法]
是什么错?发生异常吗?

热点排行