asp.net 连接数据库文件 dbf

来源:互联网 发布:js滑动效果 编辑:程序博客网 时间:2024/04/29 14:06

asp.net 可以直接连接数据库 文件,如下 :

// resolve the address to the Access database
   string fileNameString = this.MapPath(".");
   fileNameString += "..\\..\\..\\..\\data\\chartdata.mdb";

   // initialize a connection string 
   string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;
   
   // define the database query 
   string mySelectQuery="SELECT Name, Sales FROM REPS WHERE RegionID < 3;";

   // create a database connection object using the connection string 
   OleDbConnection myConnection = new OleDbConnection(myConnectionString);
   
   // create a database command on the connection using query 
   OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);
   
   // open the connection 
   myCommand.Connection.Open();
   
   // create a database reader 
   OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
   
   // since the reader implements and IEnumerable, pass the reader directly into
   // the DataBind method with the name of the Column selected in the query 

 

原创粉丝点击