文件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
答案 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 );
}