asp.net 连接 access

来源:互联网 发布:文本推荐算法 编辑:程序博客网 时间:2024/06/06 02:46

web.config中设置

 <appSettings>
    <add key="ConnStr" value="provider=microsoft.jet.oledb.4.0;data source="/>
    <add key="dbPath" value="/App_Data/zzjz.mdb"/>
  </appSettings>

 

程序中调用如下:

String connstr = System.Configuration.ConfigurationSettings.AppSettings["ConnStr"] + System.Web.HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["dbPath"]);  //链接字符串


                OleDbConnection myconn = new OleDbConnection(connstr); //定义连接对像
                myconn.Open(); //打开连接

 

//以下是输出内容的一段小程序
                String sql = "select * from zlm ";
                OleDbCommand mycod = new OleDbCommand(sql,myconn);
                OleDbDataReader rs = mycod.ExecuteReader();
                while (rs.Read()) {
                    Label1.Text =Label1.Text+"+"+ rs["title"].ToString();
                }

原创粉丝点击