Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object ref not set to an instance of an object

Status
Not open for further replies.

snejsnej

Technical User
Nov 16, 2005
21
0
0
CA
Hello all,

I've been running into the above exception and can't seem to get past it. In thread796-1043354 a similar issue came up but I'm still crapping out...

Here's my code:

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

'Declare the data access layer
Dim dataAccess As New DAL_PICUQuestionnaire.DBAccess

dataAccess.AddRecord('a bunch of drop down lists and textboxes... this is where the exception occurs)

End Sub

The DAL_PICUQuestionnaire class is as follows:

Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Security


Public Class DBAccess

'Declare the connection to the database
Protected con As New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("connection"))

Public Sub AddRecord('info from the ddl and text boxes put in here)

'Open data connection
con.Open()

'The following falls within a Try... Catch structure to handle any errors that might arise.

Try

'Declare the SQL Server command then identify it as a stored procedure type

Dim cmdAddRecord As New SqlCommand("PICU_AddRecord", con)
cmdAddRecord.CommandType = CommandType.StoredProcedure

' yadda yadda yadda

End Sub

End Class


So... any ideas about what I'm doing wrong? Thanks in advance for any help!

snejsnej
 
dataAccess.AddRecord('a bunch of drop down lists and textboxes... this is where the exception occurs)

put a break point on that line. Open the command window and type

?dataaccess

if the word "nothing" is printed, that is your problem. If a whole bunch of stuff is printed, it is not your problem. repeat this problem for each of the 'drop down lists and text boxes' it is likely that some item is not instantiated.

One common culprit is if you use the selected item or selected index of a combo box and nothing is selected. That will return nothing, and when you try to use a method of a variable that points to nothing, you get that exception.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks ThatRickGuy,

I tried your suggestion with ?dataaccess at the command window prompt, but it's telling me that the command is invalid. I tried the command in a couple different case permutations just to be sure, but no luck. In any case, there's a default value for all the drop downs, so there should be something returned. (FYI, this is how I have the drop downs listed in my dataAccess.AddRecord method: CType(ddlWhoCompletes.SelectedItem.Value, String))

Interestingly, I'm getting a lot of 'error: cannot obtain value' values showing up in the Locals window. Does this help to narrow down the problem?

Thanks again,
snejsnej
 
select dataaccess while debugging and then right click an add watch, do this for every combo and listbox. and all the ddlWhoCompletes.SelectedItem.Value thingies. one of them will show up nothing or gve an error.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Thanks Christiaan,

I did it and it worked, so that's good news. However, the not-so-good-news is that I am getting an error on all of them, the drop downs and the textboxes, any idea why this is? Specifically, it's saying "error: cannot obtain value". It seems like it should be a straight-forward process of passing the values from the various drop downs and text boxes to the AddRecord method on my data access layer, but the values aren't even showing up! hm. anyway, any help would be greatly appreciated.

snejsnej

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top