We help IT Professionals succeed at work.

SQL Invalid Column name

Hi Guys
Can you find anything wrong with this query, it says invalid column name on all the columns, I am tryinf to display the result in a gridview

Public Sub showPlaceholder()
        Dim pagesGrid As New GridView
        Using myConn As New SqlConnection(connStr)
            Dim sql As String = "SELECT [Pages.pageTitle], [Pages.pageContent], [MenuItems.MenuItemText] from " & _
                                "[Pages], [MenuItems] where [pages.siteID] = [menuitems.siteID] and " & _
                                "[menuitems.siteID] = 3"
            Dim mycommand As New SqlCommand(sql, myConn)
            Dim mydataset As New DataSet
            Dim myadapter As New SqlDataAdapter(mycommand)
            myadapter.Fill(mydataset)
            pagesGrid.DataSource = mydataset
            Dim myPlaceholder As PlaceHolder = Me.UpdatePanel3.FindControl("PlaceHolder1")
            myPlaceholder.Controls.Add(pagesGrid)
        End Using

Open in new window

Comment
Watch Question

AneeshDatabase Consultant
CERTIFIED EXPERT
Top Expert 2009

Commented:
Make sure that the columns pageTitle, pageContent ,siteID exists on "page' table also MenuItemText and SiteID in MenuItems table

Author

Commented:
Yes they all exist, and spelling is corrrect as well.
Commented:
Isn't it [Pages].[pageTitle]?

Commented:
you should add more brackets
e.g
[Pages.pageTitle] change to [Pages].[pageTitle]

hope this help

Author

Commented:
Exactly mate, thanks

Explore More ContentExplore courses, solutions, and other research materials related to this topic.