我如何能够管理与.dbf填充列表视图
本文关键字:填充 列表 视图 dbf 何能够 管理 | 更新日期: 2023-09-27 18:17:35
我试图通过c# wpf打开。dbf并将其加载到ListView
,但我没有运气。
In my ViewModel:
public void DBF()
{
var databasePath = @"C:'Users'jesson'Desktop'FLCOLU_Building_Outline_Hints_308EL_section3_2180ER_QC.dbf";
var connectionString = string.Format("DSN=dBase Files", databasePath);
OdbcConnection connection = new OdbcConnection(connectionString);
connection.Open();
var _command = connection.CreateCommand();
var query = string.Format(@"SELECT * FROM C:'Users'jesson'Desktop'FLCOLU_Building_Outline_Hints_308EL_section3_2180ER_QC.dbf");
string commandText = query;
var _dataAdapter = new OdbcDataAdapter(commandText, connection);
DataSet _dataSet = new DataSet();
DataTable _dataTable = new DataTable();
_dataSet.Reset();
_dataAdapter.Fill(_dataSet);
_dataTable = _dataSet.Tables[0];
var rows = _dataTable.Rows;
string userName = rows[0].ItemArray[1] as string;
string password = rows[0].ItemArray[2] as string;
UserDataVar = new InputDataSingle
{
UserName = userName,
Password = password
};
connection.Close();
}
我做错什么了吗?还有其他想法吗?
给你。试试下面的。
string filename= //yourfilePath;
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ filename +";Extended Properties=dBASE IV;User ID=Admin;Password=;";
DataTable dt = new DataTable();
using (OleDbConnection con = new OleDbConnection(constr))
{
var sql = "select * from " + filename ;
OleDbCommand cmd = new OleDbCommand(sql, con);
con.Open();
DataSet ds = new DataSet(); ;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
dt =ds.Tables[0]
}
如何传递数据给listview或dataGrid.;
mylistview.ItemsSource = dt.DefaultView;
你必须为ListView创建View