Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 8th, 2005, 11:32 PM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chap 17, page 609, error -- stumped

Step 12 on page 609 instructs me to click run to see the results of the previous 11 steps. The error message I get is shown in Section A below. The code that produced the error is shown in Section B below. As a companion to that, Section C is also enclosed; it’s the HTML from the exercise.

The error message is not fully clear to me. I suspect the issue is this – when it tries to execute line 61 and returns the error regarding “Line 1… near =” it may be referring to this line of code:

'Initialize the connection object

objConnection = New SqlConnection("Server=localhost;Initial Catalog=Pubs;User ID=dennis;Password=dennis;")

If it is, I’m stumped. I tested the connection using Query Analyzer and the dennis/dennis combination worked.

Am I on the right track or has my train of thought jumped the rails? Either way, help!

Thank you!


Section A

Server Error in '/DataGridSorting' Application.

--------------------------------------------------------------------------------

Line 1: Incorrect syntax near '='.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near '='.

Source Error:


Line 59: 'Initialize the DataSet object and fill it
Line 60: objDataSet = New DataSet
Line 61: objDataAdapter.Fill(objDataSet, "Authors")
Line 62:
Line 63: 'Declare a Dataview object, populate it, and sort the data in it


Source File: c:\inetpub\wwwroot\DataGridSorting\WebForm1.aspx.v b Line: 61

Stack Trace:

[SqlException: Line 1: Incorrect syntax near '='.]
   System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
   System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior behavior) +45
   System.Data.SqlClient.SqlCommand.System.Data.IDbCo mmand.ExecuteReader(CommandBehavior behavior) +5
   System.Data.Common.DbDataAdapter.FillFromCommand(O bject data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +36
   DataGridSorting.WebForm1.BindGrid(String strSortField) in c:\inetpub\wwwroot\DataGridSorting\WebForm1.aspx.v b:61
   DataGridSorting.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\DataGridSorting\WebForm1.aspx.v b:39
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731

--------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

Section B

Imports System.Data
Imports System.Data.SqlClient

Public Class WebForm1
    Inherits System.Web.UI.Page
    'Declare a Connection object that is global in scope
    Dim objConnection As SqlConnection

#Region " Web Form Designer Generated Code "
    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Protected WithEvents grdAuthors As System.Web.UI.WebControls.DataGrid

    'NOTE: The following placeholder declaration is required by the Web Form Designer.

    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

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

        'Put user code to initialize the page here
        'Initialize the connection object
        objConnection = New SqlConnection("Server=localhost;Initial Catalog=Pubs;User ID=dennis;Password=dennis;")

        'Only bind the data the first time the page is built
        'Subsequent post backs will be to sort the data in the grid
        If Not (IsPostBack) Then
            BindGrid("Last Name")
        End If

    End Sub

    Sub BindGrid(ByVal strSortField As String)
        'Declare the objects
        Dim objDataSet As DataSet
        Dim objDataAdapter As SqlDataAdapter


        'Set the SQL string
        objDataAdapter = New SqlDataAdapter( _
        "SELECT au_lname as 'Last Name', au_fname as 'First Name', " & _
        "title as 'Book Title', price AS 'Retail Price' " & _
        "FROM authors " & _
        "JOIN titleauthor.title_id = titleauthor.au_id " & _
        "JOIN titles ON titleauthor.title_id = titles.title_id " & _
        "ORDER BY au_lname, au_fname", objConnection)

        'Initialize the DataSet object and fill it
        objDataSet = New DataSet
        objDataAdapter.Fill(objDataSet, "Authors")

  'Declare a Dataview object, populate it, and sort the data in it
        Dim objDataView As DataView = objDataSet.Tables("Authors").DefaultView
        objDataView.Sort = strSortField


        'Bind the Dataview object to the DataGrid control
        grdAuthors.DataSource = objDataView
        grdAuthors.DataBind()

        'Clean up
        objDataView = Nothing
        objDataSet = Nothing
        objDataAdapter = Nothing

    End Sub

    Private Sub grdAuthors_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles grdAuthors.SortCommand

        'Bind the datagrid using the sort column requested
        BindGrid(e.SortExpression)

    End Sub

End Class



Section C



<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="DataGridSorting.WebForm1"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

                <HEAD>

                                <title>DataGrid Sorting</title>

                                <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">

                                <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">

                                <meta name="vs_defaultClientScript" content="JavaScript">

                                <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

                </HEAD>

                <body MS_POSITIONING="GridLayout">

                                <form id="Form1" method="post" runat="server">

                                                <asp:DataGrid id="grdAuthors" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 56px"

                                                                runat="server" Width="280px" Height="88px" AllowSorting="true" AlternatingItemStyle-BackColor="#00cc99"

                                                                AutoGenerateColumns="true" BackColor="#ffffff" CellPadding="3" Font-Name="Veranda" Font-Size="8pt"

                                                                GridLines="None" HeaderStyle-BackColor="#996666" HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="#ffffff"></asp:DataGrid>

                                </form>

                </body>

</HTML>
  #2 (permalink)  
Old December 8th, 2005, 11:52 PM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please disregard my post. A colleague found the error. I simply mistyped the first JOIN clause. After changing it to this

"JOIN titleauthor ON authors.au_id = titleauthor.au_id " & _

the application ran correctly.

Thank you.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap 17 error: only content controls... Torq BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 0 September 8th, 2007 10:03 AM
Problems with Chap. 17 pg.557 & 558 alk BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 2 August 19th, 2007 09:58 AM
Unable to Compile - page 17 JDGuardia BOOK: Beginning Java 2 1 July 13th, 2003 08:30 AM



All times are GMT -4. The time now is 05:29 AM.


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