OleDbCommand.TableDirect with Multiple Tables

  • Thread starter Thread starter Jay Steele
  • Start date Start date
J

Jay Steele

The Visual Studio help file says that the CommandText for an OleDbCommand
object with a CommandType of TableDirect can list multiple tables, and that
this will return a join of the listed tables.

It says the proper syntax is the list of table names separated by commas,
and with no spaces. I've tried running this against both Sql Server and
Access, and only get error messages that the table can't be found. Here are
the exact error messages:

With Sql Server:

Table does not exist.

With Jet:

The Microsoft Jet database engine cannot find the input table or query
'employee,position'. Make sure it exists and that its name is spelled
correctly.

I understand that TableDirect is not supported by the SqlClient provider,
but is it also not supported by Sql Server or Access, period? Any other
thoughts on why this isn't working?

Thanks!

--
j steele


Here's the code running against an Access table:

Dim cmdEmployeePositionSelect As New System.Data.OleDb.OleDbCommand
cmdEmployeePositionSelect.CommandType = CommandType.TableDirect
cmdEmployeePositionSelect.CommandText = "employee,position"
cmdEmployeePositionSelect.Connection = conAccess
Try
conAccess.Open()
drX = cmdEmployeePositionSelect.ExecuteReader()
Me.txtOutput.Text = ""
While drX.Read()
Me.txtOutput.Text = Me.txtOutput.Text & _
drX("Empl_LastName") & " (" & _
drX("Empl_FirstName") & ")" & ControlChars.NewLine
End While
Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
conAccess.Close()
End Try

End Sub
 
The error message you're getting sounds like a query syntax error. One
way to find out if this is the problem is to output the entire SELECT
statement to a variable and paste the text into an open instance of
the Access query designer and see if it flies.

--Mary
 
Back
Top