p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB.NET 2002/2003 Basics (http://p2p.wrox.com/forumdisplay.php?f=76)
-   -   Try it out:Ch 16 Dataset Example (http://p2p.wrox.com/showthread.php?t=25403)

flhartley February 10th, 2005 06:02 PM

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



liamfitz August 28th, 2009 07:00 AM

Leaving 'JOINS' out of SELECT Statement ?
 
If you have copy of Access, or the Microsoft database generator in VB 2008 ( SQL SERVER or whatever ) try using the design wizard to generate the S.Q.L. then copy and paste it into the program at the appropriate point. Make sure it generates the desired output in the wizard firstly. Sometimes there are slight differences in the syntax of S.Q.L. commands as expected, and that which works e.g. '%' has now replaced '*' as a 'wild-card' character when using the LIKE clause in S.Q.L. Good luck, if anything's not clear, reply to this.


All times are GMT -4. The time now is 04:16 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.