[英]The Microsoft jet database engine could not find object while reading dbf file
I am facing very strange issue.我面临着非常奇怪的问题。 I have written class to which reads dbf file through
oledb
connection.我已经编写了通过
oledb
连接读取 dbf 文件的类。 I have downloaded dbf file from internet and it is reading all data correctly.我已经从互联网上下载了 dbf 文件,它正在正确读取所有数据。
DBF file location: E:\\Projects\\SLAVE.DBF DBF 文件位置:E:\\Projects\\SLAVE.DBF
I am facing following 2 issues我面临以下两个问题
1) When I try to read other dbf file then it is reading only its table fields. 1) 当我尝试读取其他 dbf 文件时,它只读取其表字段。 it is not reading table fields data.
它不是读取表字段数据。
E:\\Projects\\line75.dbf
2) The other issue I am facing I have DBF files when I put these files in location then i am getting exception that 2)我面临的另一个问题是,当我将这些文件放在适当的位置时,我有 DBF 文件,然后我遇到了异常
microsoft jet database engine does not find required object.
microsoft jet 数据库引擎未找到所需的对象。 Are you missing some directive or path.
您是否缺少某些指令或路径。
E:\\Projects\\SDW_plnParcel.dbf
I am totally confused why it is reading SLAVE.DBF
downloaded from internet correct, why it is not reading TABLE FIELDS DATA of line75.dbf
and why it is throwing exception on SDW_plnParcel.dbf.
我很困惑为什么它正确读取从 Internet 下载的
SLAVE.DBF
,为什么它不读取line75.dbf
TABLE FIELDS DATA 以及为什么它在SDW_plnParcel.dbf.
上抛出异常SDW_plnParcel.dbf.
My class and one function for this class is as follows:我的课程和这个课程的一个功能如下:
public class dbfHandler
{
public dbfHandler()
{
this.dbfTable = new DataTable();
}
public void initconnection(String filepath) // initialise dbconnection
{
String[] splitString = filepath.Split('\\');
this.filename = splitString[splitString.Length - 1];
splitString = splitString.Where(w => w != splitString[splitString.Length - 1]).ToArray();
String folderPath = String.Join("\\", splitString);
this.dbConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + folderPath + ";Extended Properties=dBase III");
this.dbConnection.Open();
}
public List<String> getcolumnvalues(int fieldIndex, List<int> rowIndexes)
{
List<String> columnvalues = new List<string>();
try
{
if(this.dbConnection.State == ConnectionState.Open)
{
string mySQL = "select * from " + this.filename; // dbf table name
OleDbCommand MyQuery = new OleDbCommand(mySQL, this.dbConnection);
OleDbDataReader reader = MyQuery.ExecuteReader();
int rowCount = 0;
while(reader.Read())
{
bool match = rowIndexes.Any(item => item == rowCount);
if(match == true)
{
String value = reader.GetValue(fieldIndex).ToString();
columnvalues.Add(value);
}
rowCount++;
}
reader.Close();
}
}
catch(Exception e)
{
throw e;
}
return columnvalues;
}
private String filename;
private DataTable dbfTable;
private OleDbConnection dbConnection;
}
When dealing with .DBF files, I have always had better results working with Microsoft's Visual Foxpro OleDb Provider在处理 .DBF 文件时,我总是有更好的结果与Microsoft 的 Visual Foxpro OleDb Provider 一起工作
The connection string in simplified format简化格式的连接字符串
var connString = @"Provider=VFPOLEDB.1;Data Source=C:\SomePathToData;";
Now, instead of doing the data reader -- just to make sure you can get / see what you are expecting, try using a DataAdapter...现在,不要做数据读取器——只是为了确保你能得到/看到你所期待的,尝试使用 DataAdapter ......
var da = new OleDataAdapter( yourSqlCmdObject, yourConnection)
var dt = new DataTable();
da.Fill(dt);
It should pull all columns from your query and all rows into proper data column types... Then you could cycle through all the column names, rows, etc..它应该将查询中的所有列和所有行提取到正确的数据列类型中……然后您可以循环浏览所有列名、行等。
foreach( DataColumn dc in dt.Columns )
var tmp = dc.ColumnName;
foreach( DataRow dr in dt.Rows )
{
object x = dr[0]; // get VALUE from column 0
x = dr["SpecificColumn"]; // if you KNOW the column name
}
Of which, you could tweak as needed.其中,您可以根据需要进行调整。 But if you only need a SPECIFIC column (or limited columns), change your query to quantify that.
但是,如果您只需要一个特定的列(或有限的列),请更改您的查询以对其进行量化。
Select OneField from YourTable...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.