locked
readi g a .dbf file RRS feed

  • Question

  • User1618321365 posted

    I'm using the code below to read a .dbf file where the code was obtained from

    http://www.aspcode.net/Reading-DBF-files-in-C.aspx

    In my case, the app cannot locate the "airport.dbf" object  -- error is below. I've tried to use just "airport" w/o a path but it gives the same error.

                     ---Jim

    Server Error in '/GVOps4' Application.

    ERROR [42S02] [Microsoft][ODBC dBase Driver] The Microsoft Jet database engine could not find the object 'airport'.  Make sure the object exists and that you spell its name and the path name correctly.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.Odbc.OdbcException: ERROR [42S02] [Microsoft][ODBC dBase Driver] The Microsoft Jet database engine could not find the object 'airport'.  Make sure the object exists and that you spell its name and the path name correctly.

    Source Error:

    Line 396:            oCmd.CommandText = @"SELECT * FROM C:\webprojects\airports\airport"; 
    Line 397:            DataTable dt = new DataTable(); 
    Line 398:            dt.Load(oCmd.ExecuteReader()); 
    Line 399:            oConn.Close(); 
    Line 400: 

    Source File: c:\webprojects\GVOps4\App_Code\Class1.cs    Line: 398

    Stack Trace:

    [OdbcException (0x80131937): ERROR [42S02] [Microsoft][ODBC dBase Driver] The Microsoft Jet database engine could not find the object 'airport'.  Make sure the object exists and that you spell its name and the path name correctly.]
       System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode) +35
       System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod) +1735
       System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader) +60
       System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior behavior) +75
       System.Data.Odbc.OdbcCommand.ExecuteReader() +6
       dbQueries.readAirportDBF() in c:\webprojects\GVOps4\App_Code\Class1.cs:398
       _Default.Page_Load(Object sender, EventArgs e) in c:\webprojects\GVOps4\GVStaff\Orders.aspx.cs:23
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Control.LoadRecursive() +47
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
    


     

     

     

    public void readAirportDBF()

    {

    System.Data.Odbc.
    OdbcConnection oConn = new System.Data.Odbc.OdbcConnection(); oConn.ConnectionString = @"Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=C:\webprojects\airports\;Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";

    oConn.Open();

    System.Data.Odbc.OdbcCommand oCmd = oConn.CreateCommand();

    oCmd.CommandText = @"SELECT * FROM C:\webprojects\airports\airport"; DataTable dt = new DataTable();

    dt.Load(oCmd.ExecuteReader());

    oConn.Close();

     

    //dataGridView1.DataSource = dt;

    }

    Tuesday, April 8, 2008 2:38 PM

All replies

  • User2112208005 posted

    Hello,

    I ran into the same problem just now.

     

    Did you ever discover a solution to the problem?


    Thanks

    Steve 

    Sunday, February 7, 2010 4:30 AM
  • User-275064894 posted

    i think the problem is with the file path.

     

    oCmd.CommandText = @"SELECT * FROM C:\webprojects\airports\airport"; DataTable dt = new DataTable(); 

     

    should be like this

    oCmd.CommandText = @"SELECT * FROM C:\webprojects\airports\airport.dbf"; DataTable dt = new DataTable();

    Wednesday, February 17, 2010 2:17 PM
  • User-275064894 posted

    well seems like i am having problems as well. i am getting the same error. hope by looking at the code someone would be able to guide me to correct direction.

    Dim connection As OleDbConnection

    Dim command As OleDbCommand

    Dim reader As OleDbDataReader

    connection =

    New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _"Data Source=c:\OnlineApp\RapDBF\;Extended Properties=dBase III")

    connection.Open()

    command =

    New OleDbCommand("select * from c:\OnlineApp\RapDBF\DBF_RB.dbf", connection)

    reader = command.ExecuteReader()

    connection.Close()

    reader = command.ExecuteReader()

    ListView1.DataSource = reader

    ListView1.DataBind()

    reader.Close()

    command.Dispose()

    connection.Close()

    Wednesday, February 17, 2010 3:27 PM