Fill a Dataset

Posted on 2006-04-02
Last Modified: 2010-04-23
I am trying to start using ADO.Net but I can't even fill a dataset.  I am getting an error "Incorrect Syntax near User" using the following code:


Imports System.Data.SqlClient
Imports System.Windows.Forms

Module Module1

    Sub Main()
        Dim cmdUser As SqlCommand
        Dim da As New SqlDataAdapter
        Dim conn As New SqlConnection
        Dim ds As New DataSet

            ' Configure the Connection
            conn.ConnectionString = "Data Source=(Local)\SQLExpress;Initial Catalog=BTBRepIT;Integrated Security=True;Pooling=False"

            ' Configure the Command
            cmdUser = conn.CreateCommand
            cmdUser.CommandText = "Select * From User"
            cmdUser.CommandType = CommandType.Text
            da.SelectCommand = cmdUser

            ' Fill the Dataset

            MessageBox.Show("Completed Successfully")
        Catch ex As Exception
        End Try
    End Sub

End Module


I know the problem isn't the SQL statement since they don't get much simpler than that but as far as what the actual problem is I have no idea.  Thank you in advance for your help.
Question by:kmcbrearty
    LVL 10

    Accepted Solution

    try this

    "SELECT * FROM [User]"


    "SELECT * FROM ""User"""

    LVL 10

    Expert Comment

    BTW, USER is a reserved word for sql - so that's why you may be having that problem.
    LVL 3

    Author Comment

    Thank you,  that was the problem.  I usually precede my tables with tbl to aviod naming conflicts but was just creating a test to verify I was doing it correctly.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now