Wrox Programmer Forums
|
BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5
This is the forum to discuss the Wrox book Beginning Visual Basic 2005 Databases by Thearon Willis; ISBN: 9780764588945
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 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 April 27th, 2009, 03:23 PM
Authorized User
Points: 68, Level: 1
Points: 68, Level: 1 Points: 68, Level: 1 Points: 68, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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 WDABase
Try
'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 Exception
MessageBox.Show(exceptionErr.Message)
EndTry
EndUsing
End Sub
/
code
 
Old May 9th, 2009, 07:36 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

You don't say where you are getting the error. Are you getting to the Stop command or do you error before that point?

Thearon





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Create Global Subroutine or Function? Yeshey ASP.NET 3.5 Basics 3 February 17th, 2009 07:23 AM
Page 3 function versus subroutine LongJohnSilver BOOK: Professional Visual Basic 2008 ISBN: 978-0-470-19136-1 0 January 6th, 2009 04:40 PM
vb6 subroutine to ftp a file? dgr7 VB How-To 2 January 16th, 2007 12:15 AM
Function/Subroutine Pointer Parameter pjm Access VBA 3 October 3rd, 2006 09:07 AM
calling subroutine from different module? Raif Access 2 June 15th, 2004 11:56 PM





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