标题:visual studio 2005连接SQL2000数据库,哪里出错啦。高手们指点下~
取消只看楼主
gaogaoggs
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-5-8
结帖率:0
已结贴  问题点数:20 回复次数:1 
visual studio 2005连接SQL2000数据库,哪里出错啦。高手们指点下~
private void Form1_Load(object sender, EventArgs e)
        {
            string strConn = "server=.;user id=dbo;pwd=;database=admin";
            SqlConnection con = new SqlConnection(strConn);
            string sql = "select * from adminpswd";
            SqlDataAdapter ada = new SqlDataAdapter(sql, con);
            DataSet ds = new DataSet();
            ada.Fill(ds);

        }
        private void button1_Click(object sender, EventArgs e)
        {
         
            if (this.textBox1.Text == "")
            {
                MessageBox.Show("用户名不能为空!", "错误");
            }
            else if (this.maskedTextBox1.Text == "")
            {
                MessageBox.Show("密码不能为空!", "错误");
            }
            else
            {
                if (IsUser(this.textBox1.Text))
                {
                    if (this.maskedTextBox1.Text == LoginUser(this.textBox1.Text))
                    {
                        Form2 frm2 = new Form2();
                        // //frm2.showdialog();
                        frm2.Show();
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("密码错误!");
                    }
                }
                else
                {
                    MessageBox.Show("用户名错误!");
                }
            }

        }

        private string LoginUser(string uName) //检测用户是否能够登录
        {
            DataSet ds = new DataSet();
            return ds.adminpswd[0].Rows[0]["密码"].ToString();
            con.Close();
        }


        private bool IsUser(string uName) //检测用户输入的用户名是否存在
        {
            DataSet ds = new DataSet();
            ada.Fill(ds, "adminpswd");

            int n;
            n = ds.adminpswd[0].Rows.Count;
            if (n > 0)
                return true;//存在就返回true
            else
                return false;

            con.Close();
        }

        private void button2_Click(object sender, EventArgs e)//button2的 Text属性是:取消登录
        {
            Application.Exit();//用户取消登录,退出系统
        }
搜索更多相关主题的帖子: 数据库 visual studio 
2010-05-08 21:05
gaogaoggs
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-5-8
得分:0 
说是,系统知不道adminpswd...
2010-05-08 21:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-305885-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.150010 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved