触摸屏租赁
Touch screen rental
广告机租赁
Advertising rental
机器人租赁
Robot leasing
 当前位置:首页 > > C#连接带密码ACCESS数据库的方法

方法一
用WEB.CONFIG
1.在WEN.CONFIG中加入如下代码:
<appSettings>
  <add key ="oledbconacess" value="Provider=Microsoft.jet.oledb.4.0; data source={0}/App_data/bbb.mdb;User Id=admin;jet OleDB:Database Password=123"/>
  </appSettings>
2.在网页中加入如下代码:
string connstr = string.Format(ConfigurationManager.AppSettings["oledbconacess"], HttpContext.Current.Server.MapPath("."));
OleDbConnection conn = new OleDbConnection(connstr);
conn.Open();
                string sqlstr = "SELECT * FROM stu ";
        OleDbDataAdapter da = new OleDbDataAdapter(sqlstr, conn);

        DataSet ds = new DataSet();
        da.Fill(ds);
        DataTable dt = ds.Tables[0];
        GridView1.DataSource = dt;
        GridView1.DataBind();
        conn.Close();
方法二
直接在网页中
 string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;User Id=admin;jet OleDB:Database Password=123; Data Source=" + Server.MapPath("App_data\\bbb.mdb");
        OleDbConnection conn = new OleDbConnection(connstr);
        conn.Open();
        string sqlstr = "SELECT * FROM stu ";
        OleDbDataAdapter da = new OleDbDataAdapter(sqlstr, conn);

        DataSet ds = new DataSet();
        da.Fill(ds);
        DataTable dt = ds.Tables[0];
        GridView1.DataSource = dt;
        GridView1.DataBind();
        conn.Close();
方法三
使用datasource控件,不能用accessdatasource,要用SQLdatasource

 

本文来自CSDN博客,转载请标明出处:http://www.gao3.cn/asp/article/article48.htm


工作室地址:重庆石桥铺电脑城B座 | 微信:z35544216 | 网址:www.35544216.com