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
|