string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:DataBase Password="+TextBox1.Text+";User Id=admin;Data source=" + Server.MapPath("Ex07_02.mdb");
        OleDbConnection oc = new OleDbConnection(ConStr);
        try
        {
            //打开数据库连接
            oc.Open();
            OleDbDataAdapter oa = new OleDbDataAdapter("select * from tb_info", oc);
            DataSet ds = new DataSet();
            oa.Fill(ds, "tb_info");
            GridView1.DataSource = ds;
            GridView1.DataBind();
            Label1.Text = " 连接成功!";
        }
        catch(Exception error)
        {
            Label1.Text = " 密码错误,请重新输入密码!";
            return;
        }
        finally
        {
            //关闭数据库连接
            oc.Close();
        }
posted on 2010-09-09 20:33  WPF之家  阅读(365)  评论(0编辑  收藏  举报