none
OleDB syntax errors in From statement RRS feed

  • Question

  • i'm pretty new to database handling with vb.net..

     

    I have database that has a query called PT Query. Within the query there are 6 column...5 of these I wish to display in the datagridview and the sixth one in a read only text box.


    and I am trying to display it in a datagridview so I can further filter the results.

     

    Here's what I have so far

     

    Code Snippet

    Private ds As DataSet

    Private dv As DataView

    Private ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""" & LocalAppDir & "DDName.mdb"";"

    Dim Cn As OleDbConnection

     

    Private Sub usedbyfdmovedlg_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim LocalPath As String = LocalAppDir

    Dim DDName As String = "DDName.mdb"

    CheckDDName() 'This check if the database is up to date compared to a network version

    If CheckFile(LocalPath, DDName) = True Then

    Cn = New OleDbConnection(ConStr)

    Cn.Open()

    ds = New DataSet

    dv = New DataView

    Dim ad As New OleDbDataAdapter("SELECT * FROM PT Query", Cn)

    ad.Fill(ds, "PT Query")

    dv.Table = ds.Tables("PT Query")

    Me.FedMoveView.DataSource = dv

    End If

    End Sub

     

    So i am getting an exception at ad.fill(ds...)...

    saying that there's a syntax error when I dim ad

     

    any help and guidance appreciated.

    Wednesday, June 13, 2007 3:24 PM

Answers

  • All right I figured it out..

     

    I guess SQL gets confused sometimes with spaces.

    Changed "Select * FROM PT Query" to "Select * FROM [PT Query]"

    And that did the trick

    Wednesday, June 13, 2007 5:37 PM

All replies

  • All right I figured it out..

     

    I guess SQL gets confused sometimes with spaces.

    Changed "Select * FROM PT Query" to "Select * FROM [PT Query]"

    And that did the trick

    Wednesday, June 13, 2007 5:37 PM
  • It is not really confused. Spaces are not valid characters in identifiers and to make them valid you need to put them into square brackets. Same true in a case if you have any column or table names that are reserved words in SQL Server, for example Date

    Thursday, June 14, 2007 3:03 AM
    Moderator