Unhandled Exception of type System.Data.SqlClient.SqlException occured in system.data.dll

Hello,

I keep getting excetion errors when i run this code, any ideas why ?

Thanks



Imports System.data
Imports System.Data.SqlClient

Public Class Form1
    Inherits System.Windows.Forms.Form


    Dim oConnection As SqlConnection = New SqlConnection("server=1997UK-FIN02;database=pubs;user id=sa;password=orange")
    Dim oDataAdapter As New SqlDataAdapter
    Dim oDataset As DataSet = New DataSet

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

        oDataAdapter.SelectCommand = New SqlCommand
        oDataAdapter.SelectCommand.Connection = oConnection
        oDataAdapter.SelectCommand.CommandText = _
            "SELECT dbo.authors.au_lname, dbo.authors.au_fname, dbo.titles.title, dbo.titles.price" & _
            "FROM dbo.authors INNER JOIN dbo.titleauthor ON dbo.authors.au_id = dbo.titleauthor.au_id " & _
            "INNER JOIN dbo.titles ON dbo.titleauthor.title_id = dbo.titles.title_id"

        oDataAdapter.SelectCommand.CommandType = CommandType.Text

        'Open the database connection...
        oConnection.Open()

        'Close the Connection
        oConnection.Close()

        'Fillthe DataSet object with data
        oDataAdapter.Fill(oDataset, "authors")


        'Set the Data grid properties to bind it to our data
        grdAuthorTitles.DataSource = oDataset
        grdAuthorTitles.DataMember = "authors"

        'Clean up
        oDataAdapter = Nothing
        oConnection = Nothing

    End Sub
End Class



Thank-you
show_tAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeff CertainCommented:
What error? What line errors? Have you tried stepping through your code?

Also, try this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim strSQL as String = _
            "SELECT dbo.authors.au_lname, dbo.authors.au_fname, dbo.titles.title, dbo.titles.price" & _
            "FROM dbo.authors INNER JOIN dbo.titleauthor ON dbo.authors.au_id = dbo.titleauthor.au_id " & _
            "INNER JOIN dbo.titles ON dbo.titleauthor.title_id = dbo.titles.title_id"
    Dim cmd as New SQLCommand(strSQL,oConnection)
    Dim oDataAdapter As New SqlDataAdapter(cmd)
    Dim oDataset As New DataSet
    'Fillthe DataSet object with data
    oDataAdapter.Fill(oDataset, "MARKETS")
End Sub
Jeff CertainCommented:
Oh... and fix the missing space at the end of the first line in the SQL string...
"SELECT dbo.authors.au_lname, dbo.authors.au_fname, dbo.titles.title, dbo.titles.price " & _
            "FROM dbo.authors INNER JOIN dbo.titleauthor ON dbo.authors.au_id = dbo.titleauthor.au_id " & _
            "INNER JOIN dbo.titles ON dbo.titleauthor.title_id = dbo.titles.title_id"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
show_tAuthor Commented:
That was it !

Thanks
Nice easy one for you

:-)
Jeff CertainCommented:
Glad I could help... thanks for the points... finally made guru :):)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.