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();
}
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();
}
作者:wpf之家
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。