C# DBF To/转换为 DataSet DataTable

        public DataSet GetDbfData(string sFileName,string tableName)
        {
            //string strConnection = @"Dsn=Visual FoxPro Tables;sourcedb=" + sFileName.Substring(0, sFileName.LastIndexOf("//")) + ";sourcetype=DBF;exclusive=No;backgroundfetch=Yes;collate=Machine";
            string strConnection = GetConnection(sFileName);
            //对于连接串,注意版本问题

            string strSelect = "SELECT * FROM  " + tableName + " WHERE THISNUM > 0 ";

            OleDbConnection thisConnection = new OleDbConnection(strConnection);

            thisConnection.Open();

            OleDbDataAdapter thisAdapter = new OleDbDataAdapter(strSelect, thisConnection);

            DataSet thisDataSet = new DataSet();

            try
            {

                thisAdapter.Fill(thisDataSet);

            }

            catch (Exception exec)
            {

                MessageBox.Show(exec.Message);

            }

            return thisDataSet;
        }

 

        private string GetConnection(string path)
        {

            return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=dBASE IV;";

        }

你可能感兴趣的:(C# DBF To/转换为 DataSet DataTable)