none
Can't open database file *.dbf RRS feed

  • Question

  • 1#
    using (OleDbConnection _connection = new OleDbConnection())
                {
                    var ConnectionString = new StringBuilder("");
                    ConnectionString.Append(@"Provider=Microsoft.Jet.OLEDB.4.0;");
                    ConnectionString.Append(@"Extended Properties=dBASE IV;");
                    ConnectionString.Append(@"Data Source=D:\TT\ByteEnterprise2;");
                    _connection.ConnectionString = excelConnection;//ConnectionString.ToString();
                    _connection.Open();
    
                    using (OleDbDataAdapter da = new OleDbDataAdapter(sql, _connection))
                    {
                        using (DataSet dsRetrievedData = new DataSet())
                        {
                            da.Fill(dsRetrievedData);
                            var a = dsRetrievedData.GetXml();
                        }
                    }
                }
    2#
                OleDbConnection conn;
                OleDbDataAdapter oledbAdapter;
                DataSet ds;
                OleDbCommand cmd;
                ds = new DataSet();
                string connetionString = null;
                string strFileName = "ATTACHMT11.dbf";
                connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + "; Extended Properties=dBASE IV;";
                conn = new OleDbConnection(connetionString);
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                   
                }
                string Sql = "select * from " + strFileName;
                oledbAdapter = new OleDbDataAdapter(Sql, conn);
                try
                {
                    oledbAdapter.Fill(ds);
                }
                catch (Exception ex)
                {
                }

    I try to read data from a some file. But on this string ".Fill()" I have an error: "External table is not in the expected format". Maybe file have a incorrect encoding or something else. Exel can't open this file and Access too. But third-party program can open this file or convert into xls.

    What am I doing wrong?

    Friday, December 25, 2015 8:26 AM

All replies