Link to home
Start Free TrialLog in
Avatar of show_t
show_t

asked on

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
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of show_t
show_t

ASKER

That was it !

Thanks
Nice easy one for you

:-)
Glad I could help... thanks for the points... finally made guru :):)