0

我正在尝试通过 c# wpf 打开 .dbf 并将其加载到 .dbf 中ListView,但我没有运气。

在我的视图模型中:

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();

    }

我做错什么了吗?还有其他想法吗?

4

1 回答 1

0

干得好。试试下面的一个。

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;

于 2013-06-08T16:06:11.120 回答