retrieving "Data" from Listbox

bob.walker

Member
Joined
May 17, 2005
Messages
18
Programming Experience
3-5
The following code is me loading a listbox with a table. I have no problem with the retrieving data if data has information, but if the field is empty I get a error. how can I check the field in a listbox first for DBnull?

'***1. load listbox from table

vStr = "Select social&' '&name as entry, title, street, RowNumber"
vStr += " from EmpAdds where "
vStr += " id_code = " + CType(cbEMPL.SelectedValue, String)

oCont = VB_LIB.MAIN.SQLSelect(vStr, oACC)

If oCont.Rows.Count > 0 Then
Me.lbOwnrInfo.DataSource = oCont
Me.lbOwnrInfo.DisplayMember = "entry"
Me.lbOwnrInfo.ValueMember = "RowNumber"
endif

'***2. Get Data from Listbox

temp = me.lbOwnrInfo.SelectedItem("street")

Thanks for any help!
 
Something like this?

If Not cbEMPL.SelectedValue Is DBNull.Value Then

Else

End If


You should check for null before you load the listbox, since loading nothing into the listbox makes no since.


Hope this helps
 
Not clear enough, sorry.

The loading of the list box works fine. I have the problem when tring to get one of the fields in the listbox not used as "DisplayMember" or "ValueMember". I am trying to get the value of "street".
 
See If I have this right,

You load a listbox from a table, make a selection and want to use one of the fields you loaded to do something else with.

You want to use the listbox like a datagrid, and be able to access each field loaded - why not use a datagrid. Otherwise you would have to use the selection to access the correct record to get to the field you want.

perhaps load the listbox with just names, select a name, use the name in a select statement to access the matching record of the dataset and have access to all the information that way.
 
I know I was tring to take the easy way :( I changed to grab the value and do another select statement to get my information.

Thanks for the help.
 
Back
Top