Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    1

    Unanswered: query dbase IV in vb.net

    hi,
    I am attemping to query a .dbf file, and have been beating my head against the wall trying to figure out the problem.

    I'm nearly positive I have the connection string correct, because my error is not related to finding the .dbf. I keep getting an "incomplete query" error regarding the syntax of (for starters) a very easy "SELECT * FROM abc.dbf" statement. The error occurs on the executereader statement.

    I've tried removing the single quotes (and also adding double quotes) around the table name - error in finding the table

    I've tried enclosing the table name in [] - error in finding table

    I've tried using the full path (c:\myfolder\mytable.dbf) - error in finding the table

    1) Is this the best/fastest/most efficient method for connecting to this dbf for querying?

    2) What the heck am I doing wrong?

    thanks - Mike

    ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source= " & foldername & ";Extended Properties=dBase IV;"

    Dim dBaseConnection As New System.Data.OleDb.OleDbConnection(ConnectionString )
    dBaseConnection.Open()

    Dim myquery As String

    myquery = "SELECT * FROM '" & tablename & "';"

    Dim dBaseCommand As New System.Data.OleDb.OleDbCommand(myquery, dBaseConnection)

    Dim dBaseDataReader As System.Data.OleDb.OleDbDataReader = dBaseCommand.ExecuteReader(CommandBehavior.Sequent ialAccess)

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    You should not use text delimiters (') around object (table) names.

    Try changing
    Code:
    myquery = "SELECT * FROM '" & tablename & "';"
    to

    Code:
    myquery = "SELECT * FROM " & tablename
    The only exception to this rule is when the database server uses case sensitive object naming rules, and when it automatically folds unquoted object names to a case which is different than what you entered.

    PostgreSQL, for instance, folds unquoted object names to lower case.

    If you had a table named "Test" and you entered Select * from Test, it would not be able to find the table, but, if you used Select * From "Test", then, it would find the object(, if it existed.)
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •