找不到可安装的 ISAM 之 C#读取VFP数据
看到博问上一C#读取VFP数据的提问,试图解决一下,之前有点印象,于是写代码小试一下;
首先要安装VFPOledb 的oledb provider,到微软官方下载;
安装完毕,基于这个Provider的例程数据库Northwind ,测试代码如下:
转载请注明:http://www.cnblogs.com/winzheng/archive/2009/07/11/1521435.html
1 public void OpenVFP()
2 {
3 OleDbConnection objConn = new OleDbConnection();
4 OleDbDataAdapter SQLada;
5 objConn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;"+
6 "DataSource= C:\VFP\Samples\Northwind;"+ //这是本机安装Provider的路径
7 "Extended Properties='dBASE 5.0'";
8 objConn.Open();
9 OleDbCommand cmd = new OleDbCommand();
10 cmd.CommandType = CommandType.Text;
11 cmd.CommandText =
12 "select * from employeeterritories";//employeeterrITories.dbf
13 SQLada = new OleDbDataAdapter(cmd);
14 }
2 {
3 OleDbConnection objConn = new OleDbConnection();
4 OleDbDataAdapter SQLada;
5 objConn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;"+
6 "DataSource= C:\VFP\Samples\Northwind;"+ //这是本机安装Provider的路径
7 "Extended Properties='dBASE 5.0'";
8 objConn.Open();
9 OleDbCommand cmd = new OleDbCommand();
10 cmd.CommandType = CommandType.Text;
11 cmd.CommandText =
12 "select * from employeeterritories";//employeeterrITories.dbf
13 SQLada = new OleDbDataAdapter(cmd);
14 }
运行程序:报出找不到可安装的 ISAM ;
呵呵,没遇见过,搜之......
DataSource= C:\VFP\Samples\Northwind; 应该是Data Source= C:\VFP\Samples\Northwind;
把空格吃掉了,总之你的连接串一定不能写错,否则就会报这个错误。
类似的问题也会在如下情况发生,例如你的“Excel 12.0;HDR=Yes;IMEX=1” 如果少加了引号也会得到这个结果:
OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\upload\2009070512123000005.xls;Extended Properties='Excel 12.0;HDR=Yes;IMEX=1';");
建议还是把常用连接做成一个模板,不但要记在心中,最好用的时候直接粘贴,否则小的疏忽会导致大的损失。
转载请注明原创位置:http://www.cnblogs.com/winzheng/archive/2009/07/11/1521435.html