Wrox Programmer Forums
|
BOOK: Beginning VB.NET Databases
This is the forum to discuss the Wrox book Beginning VB.NET Databases by Thearon Willis; ISBN: 9780764568008
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 15th, 2005, 03:29 PM
Registered User
 
Join Date: Aug 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default new ch. 6 question

I am at the part where Time Tracker will display the project details at the bottom of the page for the item that you select in the listview control.

The program will only add the first item in the list to the details. No matter which one I select, it only shows details for the first item in the whole list. I've made sure that the tag is correct in the load procedure. I've also verified that the datareader is only grabbing one line. I don't know how the program is doing this. Any ideas about where I may have messed up?

my code:

Private Sub LoadProjects()
        'Declare variables
        Dim objListViewItem As ListViewItem

        'Initialize a new instance of the data access base class
        objData = New DALBase

        Try
            'Gel all projects in a DataReader object
            objData.SQL = "usp_SelectProjects"
            objData.InitializeCommand()
            objData.OpenConnection()
            objData.DataReader = objData.Command.ExecuteReader

            'See if any data exists before continuing
            If objData.DataReader.HasRows Then
                'Clear previous list
                lvwProjects.Items.Clear()
                'Process all rows
                While objData.DataReader.Read()
                    'Create a new ListViewItem
                    objListViewitem = New ListViewItem
                    'Add the data to the ListViewItem
                    objListViewitem.Text = objData.DataReader.Item("ProjectName")
                    objListViewItem.Tag = objData.DataReader.Item("ProjectID")
                    'Add the sub items to the listview item
                    objListViewitem.SubItems.Add(objData.DataReader.It em("ProjectDescription"))
                    objListViewitem.SubItems.Add(objData.DataReader.It em("SequenceNumber"))
                    objListViewitem.SubItems.Add(Format(objData.DataRe ader.Item("LastUpdateDate"), "g"))
                    'Add the ListViewItem to the ListView Control
                    lvwProjects.Items.Add(objListViewitem)
                End While
            End If

            objData.DataReader.Close()
        Catch ExceptionErr As Exception
            MessageBox.Show(ExceptionErr.Message, strAppTitle)
        Finally
            'Cleanup
            objData.Dispose()
            objData = Nothing
            objListViewitem = Nothing
        End Try
    End Sub

    Private Sub lvwProjects_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvwProjects.Click
        'Initialize a new instance of the data access base class
        objData = New DALBase

        Try
            'Get the specific project selected in the ListView control
            objData.SQL = "usp_SelectProjects"
            objData.InitializeCommand()
            objData.AddParameter("@ProjectID", OleDb.OleDbType.Guid, 16, lvwProjects.SelectedItems.Item(0).Tag)
            objData.OpenConnection()
            objData.DataReader = objData.Command.ExecuteReader

            'See if any data exists before continuing
            If objData.DataReader.HasRows Then
                'Read the first and only row of data
                objData.DataReader.Read()

                'Populate the Project Details section
                txtProjectID.Text = objData.DataReader.Item("ProjectID").ToString.ToUp per
                txtProjectName.Text = objData.DataReader.Item("ProjectName")
                txtProjectDescription.Text = objData.DataReader.Item("ProjectDescription")
                txtSequenceNumber.Text = objData.DataReader.Item("SequenceNumber")
                txtProjectUpdateDate.Text = Format(objdata1.DataReader.Item("LastUpdateDate"), "g")
            End If

            objdata1.DataReader.Close()
        Catch ExceptionErr As Exception
            MessageBox.Show(ExceptionErr.Message, strAppTitle)
        Finally
            'Cleanup
            objData.Dispose()
            objData = Nothing
        End Try
    End Sub

(in DALBase class)
Public Sub AddParameter(ByVal Name As String, ByVal Type As OleDbType, _
        ByVal Size As Integer, ByVal Value As Object)
        Try
            Command.Parameters.Add(Name, Type, Size).Value = Value
        Catch OleDbExceptionErr As OleDbException
            Throw New System.Exception(OleDbExceptionErr.Message, _
                OleDbExceptionErr.InnerException)
        End Try


Thanks,

Dennis

 
Old August 16th, 2005, 04:20 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Dennis,

At first glance your code looks correct except for the line of code that closes the DataReader in the lvwProjects_Click procedure; objdata1 should be objData. My suggestion would be to set a break point in the lvwProjects_Click procedure and see what you are getting back in the lvwProjects.SelectedItems.Item(0).Tag property when you click the various items. Then step through your code and see what the data reader is pulling back.

I hope this helps.

Thearon
 
Old August 16th, 2005, 05:27 PM
Registered User
 
Join Date: Aug 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for looking that over. It turns out that I was calling the wrong stored procedure. I was calling "usp_SelectProjects" when it should have been "usp_SelectProject".

Dennis






Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch. 11 Email setup question amenne20 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 October 1st, 2006 04:04 PM
Ch. 11 Email setup question amenne20 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 1st, 2006 04:03 PM
Ch 2 example 2-5 question Bo BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 3 August 16th, 2006 07:44 AM
CH 3 pg 96 Question mririe BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 8 August 25th, 2004 04:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.