2010-09-03 97 views
0

我想是这样的:如何使用c#处理.dbf文件?

 string pathFiles = Path.Combine(Application.StartupPath, "DB"); 
     string strconn = "Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;" + 
       "Dbq="+pathFiles+";";      
     OdbcConnection odbconn = new OdbcConnection(strconn); 
     odbconn.Open(); 

和我得到这个例外

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

的问题是,同样的代码运行正常的XP,Visual Studio 2010中,Office 2007和windiws它在windows 7 64bit,visual studio 2008,office 2010上不起作用。 我真的不知道whatvis的区别,我是新的赢了7. 一些提示会很棒。谢谢。

+1

Windows 7机器是64位的吗? – 2010-09-03 19:06:51

+0

是的,Windows 7是64位 – jane 2010-09-03 19:09:12

+0

要跟踪w/Mike的评论,你可以检查并看看你是否得到不同的行为,如果你设置你的项目目标Platorm生成设置从任何CPU到x86。某些数据库驱动程序不存在于64位平台中。 – 2010-09-03 19:22:45

回答

0

对于它的价值,我在Vista和Windows 7上使用以下连接操作dBase文件。我仍将目标输出设置为x86。

using (OleDbConnection connection = new OleDbConnection(string.Format("Provider=Microsoft.JET.OLEDB.4.0;" + 
    "Data Source={0};Extended Properties=dBase IV;", Path.Combine(Environment.CurrentDirectory, OutputFolderName)))) 
{ 
    //.... 
    //.... 
} 

输出文件夹名称就是我要写入或读取的DBase文件的目录。