Listbox problems

  • Thread starter Shannon Ramirez
  • Start date
S

Shannon Ramirez

I have a dataset that I'm trying to populate to a list box. Here is
the code I'm using

Dim dsSurgeon As New DataSet
dsSurgeon = ws.fnSurgeonSEL(0, 1)


With Me.lbSurgeon
.DataSource = dsSurgeon.Tables("SurgeonSEL")
.DisplayMember = "vcSurgeonName"
.ValueMember = "intTblSurgeonId"
End With
End Sub

it blows up on me at the datasource line. It's telling me something
about system.nullreferrence

the dataset is getting created by a webservice and when I debug the
webservice, that dataset (fnSurgeonSEL) is getting populated with
data. Any idea what I'm doing wrong in my code. I have instantiated
the ws reference (I think that is the right term) to the webservice
and am using this webservice to populate a datagrid.. it's a different
function though.

any help would be great
thanks
shannon
 
S

Shannon Ramirez

in working on it more.. I took the same webservice and way I was
trying to populate the list box and put it in another project, and it
worked fine.. but when I try to do it in this project, I get this
error.

An unhandled exception of type 'System.NullReferenceException'
occurred

does this help.. can someone tell me what I've got set wrong with this
project..

thanks
 
W

William Ryan eMVP

My guess is that you aren't getting a Dataset back from your web service.
NullReferenceExceptions occur when you declare something but don't
instantiate it and try referencing it.

Check is dsSurgeon Is Nothing before the With statement.
 
S

Shannon Ramirez

I haven't tried checking for a null yet.. but I did try adding a
refference to this web service in another project. I grabbed the code
from below and made sure my list box and when I instantiated it was
the same as below and it worked... does that give you any more info
to help. I'll try checking for nulls here in a bit

thanks
shannon
 
S

Shannon Ramirez

William... I added the following line to the code below
If dsAnesthesiologist Is Nothing Then
MsgBox("It's blank")
Else
With Me.lbAnesthesiologist
.DataSource =
dsAnesthesiologist.Tables("AnesthesiologistSEL")
.DisplayMember = "vcAnesthesiologistName"
.ValueMember = "intTblAnesthesiologistId"
End With
End If

I did a breakpoint so I coudl watch and it does not show
dsAnesthesiologist as equal to nothing.. it jumps over to the else.
Here is what I'm using to instantiate teh webservice..

Dim ws As New wsMedicalCE.dataAccess

i'm using that same line in anther form with a different function and
that one is working.

Hope you have some ideas
 
S

Shannon Ramirez

very sorry to all who spent time trying to figure this one out for me.
I figured out what the problem was. I was passing in a value from
another form, using the public sub new with mybase.new and I forgot to
put the initializecomponent() in there.. that was what was causing me
the problem.. I created a new form and started with the basics and
worked up to where my other form stopped working.. and there the
problem was.. again so sorry about that
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top