View Single Post
  #1 (permalink)  
Old February 10th, 2005, 06:02 PM
flhartley flhartley is offline
Registered User
 
Join Date: Feb 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Try it out:Ch 16 Dataset Example

Help!

I am going through the book and I am working with a microsoft SQL server 2000.

I get an error when I try to run the DataSet Example but only when I try to use the JOIN command. If I leave that out, it runs fine. What am I doing wrong?:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        objDataAdapter.SelectCommand = New SqlCommand
        objDataAdapter.SelectCommand.Connection = objConnection


        objDataAdapter.SelectCommand.CommandText = "SELECT au_lname, au_fname, title, price " & _
     "FROM authors " & _
     "JOIN titleauthor ON authors.au_id = titleauthor.au_id " & _
     "JOIN titles ON titleauthor.title_id = titles.title_id " & _
     "ORDER BY au_lname, au_fname"

        objDataAdapter.SelectCommand.CommandType = CommandType.Text

        Try
            objConnection.Open()
        Catch b As SqlException
            Dim errorMessages As String
            Dim i As Integer

            For i = 0 To b.Errors.Count - 1
                errorMessages += "Index #" & i.ToString() & ControlChars.NewLine _
                               & "Message: " & b.Errors(i).Message & ControlChars.NewLine _
                               & "LineNumber: " & b.Errors(i).LineNumber & ControlChars.NewLine _
                               & "Source: " & b.Errors(i).Source & ControlChars.NewLine _
                               & "Procedure: " & b.Errors(i).Procedure & ControlChars.NewLine
            Next i

            Dim log As System.Diagnostics.EventLog = New System.Diagnostics.EventLog
            log.Source = "My Application"
            log.WriteEntry(errorMessages)
            Console.WriteLine("An exception occurred. Please contact your system administrator.")
        End Try

        objDataAdapter.Fill(objDataset, "authors")
        objConnection.Close()
        grdAutherTitles.DataSource = objDataset
        grdAutherTitles.DataMember = "authors"

        objDataAdapter = Nothing
        objConnection = Nothing


Reply With Quote