Asp.net读取文件.dbf错误conn.Open()

时间:2013-09-26 15:19:21

标签: c# asp.net visual-foxpro

文件dbf:C:\ myTable.dbf; 代码:

var file = @" C:\myTable.dbf";
var connectionString = @"Provider=vfpoledb;Data Source=" + file + ";Collating Sequence=machine;";
OdbcConnection conn = new OdbcConnection(connectionString);
conn.Open();

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

1 个答案:

答案 0 :(得分:1)

您可以尝试更改连接字符串提供程序

试          {          string conString =“Provider = Microsoft.Jet.OLEDB.4.0; Data Source = c:\ ZIP.DBF; Extended Properties = dBase IV”;          OleDbConnection conn = new OleDbConnection(conString);          command = conn。 CreateCommand();

     // create the DataSet
     DataSet ds = new DataSet ( );
     dataGridView1 . DataSource = null;

     // open the connection
     conn . Open ( );
     string commandString = "Select * from  ZIP.DBF";
     // run the query
     command . CommandText = commandString;
     OleDbDataAdapter adapter = new OleDbDataAdapter ( command );
     adapter . Fill ( ds );

     // close the connection
     conn . Close ( );

     // set the grid's data source
     dataGridView1 . DataSource = ds . Tables [ 0 ];
     }
 catch ( Exception ex)
     {
     MessageBox . Show (  ex . Message );

     }