|

April 27th, 2009, 03:23 PM
|
|
Authorized User
|
|
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
AddParameter subroutine problem
I am developing a Visual Basic front end for an Access database containing approximately 3500 records of contacts in my amateur radio log. The program will be patterned after the Project Time Tracker program and using the WDABase program in the WROX books on database programming. The contact screen will have two panels, the lower panel with a listview control showing the basic data for each contact of a particular station entered on a previous screen called CallSignInput. If I want more data on a particular contact, I will select the contact from the listview and the full data will show on the details panel in the upper half of the form. An example of the Call Sign Input would be âN7NDâ.
My problem is that after I input the selected call sign and move on to the ShowContact form of the program, I get an exception error saying âObject reference not set to an instance of the object.â A copy of the code I am using is contained below. The usp_SelectContacts query text is:
SELECT CONTLOG.ContactID, CONTLOG.STATE, CONTLOG.STATION, CONTLOG.CONTACTDATE, CONTLOG.CONTACTTIME, CONTLOG.FREQ, CONTLOG.MODE, CONTLOG.COUNTRYNAM, CONTLOG.QSLRCVD
FROM CONTLOG
WHERE CONTLOG.STATION LIKE @STATION
ORDER BY CONTLOG.ContactID;
I inserted the âStopâ command to step through the commands leading to the loading of the datareader. I am assuming my error is in defining the values for my AddParameter command. Can anyone help?
Greenbriar
code
PrivateSub frmShowCallSign_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load'Declare the variables
Dim objListViewItem As ListViewItem
Dim strSelectedStation AsString
Dim intStationLen AsInteger
'Initialize a new instance of the data access base class
Using objData AsNew WDABaseTry'Get all contacts into a Data Reader object
strSelectedStation = frmCallSignInput.txtCallSignInput.Text
intStationLen = Len(strSelectedStation)
objData.SQL = "usp_SelectContacts"
objData.InitializeCommand()
Stop
objData.AddParameter("@Station", OleDbType.Char, intStationLen, strSelectedStation)
objData.OpenConnection()
objData.DataReader = objData.Command.ExecuteReader
'See if any data exists before continuint
If objDataReader.HasRows Then'Clear previous list
lvwContacts.Items.Clear()
'Process all rows
While objDataReader.Read'Create a new ListViewItem
objListViewItem = New ListViewItem
'Add the data to the ListViewItem
objListViewItem.Text = objDataReader.Item ("CONTACTID").ToString
'Add the subitems to the listview item
objListViewItem.SubItems.Add(objDataReader.Item("STATION"))
objListViewItem.SubItems.Add(objDataReader.Item("STATE"))
objListViewItem.SubItems.Add(objDataReader.Item("CONTACTDATE"))
objListViewItem.SubItems.Add(objDataReader.Item("CONTACTTIME"))
objListViewItem.SubItems.Add(objDataReader.Item("FREQ"))
objListViewItem.SubItems.Add(objDataReader.Item("MODE"))
objListViewItem.SubItems.Add(objDataReader.Item("QSLRCVD"))
objListViewItem.SubItems.Add(objDataReader.Item("COUNTRYNAM"))
'Add the ListViewItem to the ListView control
lvwContacts.Items.Add(objListViewItem)
EndWhile
EndIf
Catch exceptionErr As ExceptionMessageBox.Show(exceptionErr.Message)
EndTry
EndUsing
End Sub
/code
|