Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Access Records From VB.net 1

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
I tried this post in another forum, but thought maybe someone here can help me out.
I am having trouble selecting data from an access table. I can select from other tables in the database, but not one named "GENERAL". Is this table name a problem and do I have to qualify it somehow? When I run the code I get an error.
ErrorCode=-2147217900
Message="Syntax error in FROM clause."
Source="Microsoft JET Database Engine"
Error Item is: "In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.

I have searched and found a non-existent table may cause this error. I know the table exists because I can open it in Access. I am using the following VB.net code that works just fine if I substitute another table name for GENERAL. I also tried qualifying the field names with "GENERAL.", but that didn't help either.

Just found something else. There is a "+" to the left of the record when viewing the file in Access. Clicking on the "+" sign displays some related records below the record. Is this stopping me from reading the file from VB.net? Is there a way around this?
Code:
' Selection String
    Dim SelString As String
    SelString = "Select TD From General"
 
    ' Connection & Command Setup
    Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Program Files\GIS Viewer\Database\Viewer.mdb"
    Dim myAccessConn As OleDb.OleDbConnection = New OleDb.OleDbConnection(myConnString)
    Dim myCommand As OleDb.OleDbCommand = New OleDb.OleDbCommand(SelString, myAccessConn)
    myCommand.CommandType = CommandType.Text

    ' Get Data
    Dim myDataSet As DataSet = New DataSet
    Dim mySqlAdapter As New OleDb.OleDbDataAdapter(myCommand)
    mySqlAdapter.Fill(myDataSet)

    MessageBox.Show(myDataSet.Tables(0).Rows.Count.ToString)

    Dim nn As Integer = 0
    While nn < 10
      MessageBox.Show(myDataSet.Tables(0).Rows(nn).Item("TD").ToString)
      nn = nn + 1
    End While

    ' Clean Up
    If Not (mySqlAdapter Is Nothing) Then
      mySqlAdapter.Dispose()
      mySqlAdapter = Nothing
    End If
    If Not (myCommand Is Nothing) Then
      myCommand.Dispose()
      myCommand = Nothing
    End If
    If Not (myAccessConn Is Nothing) Then
      If myAccessConn.State = ConnectionState.Open Then
        myAccessConn.Close()
      End If
      myAccessConn.Dispose()
      myAccessConn = Nothing
    End If


Auguy
Northwest Ohio
 
Thanks Joe. Worked perfectly. I thought it might be something like that, but wasn't sure of the syntax to make it work.

Auguy
Northwest Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top