本文介绍了将DBF文件导入C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


我使用以下源代码将dbf(DBASE)文件导入C#数据集,并且出现错误外部表格不是预期的格式 。我错过了什么?我该怎么办?



hi
I am using the following source code to import a dbf (DBASE) file into C# dataset and it is giving the error ''External table is not in expected format''. What have I missed? What should I do?

if (ofdDBF.ShowDialog()==DialogResult.OK) 
            { 
                string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ofdDBF.FileName.Substring(0, ofdDBF.FileName.LastIndexOf("\\")) + ";Extended Properties=dBASE IV;"; 
 
                OleDbConnection conn = new OleDbConnection(connStr); 
                conn.Open(); 
 
                string cmd_string = "select * from " + ofdDBF.SafeFileName.Substring(0, ofdDBF.SafeFileName.IndexOf(".")); 
                MessageBox.Show(cmd_string); 
                OleDbDataAdapter da = new OleDbDataAdapter(cmd_string, conn); 
                DataSet ds = new DataSet(); 
                da.Fill(ds); 
                dgvImport.DataSource = ds.Tables[0]; 
 
            } 





请帮助

问候

Nirmala Saravanan



Pls Help
Regards
Nirmala Saravanan

推荐答案

Imports Microsoft.Data.Odbc
...
...	
Dim cn As OdbcConnection = New OdbcConnection()
cn.ConnectionString = "DRIVER={Microsoft dBase Driver (*.dbf)};Deleted=1"
cn.Open()
Dim obCommand As OdbcCommand
Dim strSQL As String = "SELECT ID,text_type,text_line,text_data FROM " & strPath & strSource_DBF_Filename
obCommand = New OdbcCommand(strSQL, cn)



注意:ID,text_type,text_line,text_data是我的DBF文件中的列名。



经过测试:Visual Basic .NET 2003





[]

[]

[]

[]


Note: ID,text_type,text_line,text_data are columns names in my DBF file.

Tested: Visual Basic .NET 2003


Microsoft ODBC Desktop Database Drivers[^]
dBASE Driver Programming Considerations[^]
dBASE Data Types[^]
Setting Options Programmatically for the dBASE Driver[^]


这篇关于将DBF文件导入C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 09:05