Using a Listview to Populate a combo box

  • Thread starter Thread starter Dave McKie
  • Start date Start date
D

Dave McKie

Hi all

I am trying to Populate a combo box from a selection in an adjacent
Listview. The Listview lists as a string the field names of 4
different fields in tblFile. So far I can populate the combo box with
the correct number of records(only 4 in the test database) but the
data is the actual string being passed which is actually the right
field....just not the data in the field. Here is my code so far that
fills the combo box with the string Name.

' selects the field name used for the table tblFile
strID = lvSearchBy.SelectedItems(0).SubItems(1).Text
intID = CInt(Val(Trim(strID)))

'Gets field name from tblSearch
dbCmd.CommandText = "Select ActualName from tblSearch where IDKey = "
& intID & " "

dbConn.Open()
dbReader = dbCmd.ExecuteReader()
dbReader.Read()
strName = Trim(dbReader!ActualName)
dbConn.Close()
dbReader.Close()

dbConn.Open()
dbCmd.CommandText = "Select '" & strName & "' from tblFile order by '"
& strName & "' "

dbReader = dbCmd.ExecuteReader()
cboSearch.Items.Clear()
Do While dbReader.Read()
cboSearch.Items.Add(dbReader(0))
Loop
dbConn.Close()


Result in the combo box is:

wkrName
wkrName
wkrName
wkrName

There are 4 records in the test database.....so the number of records
are correct. I need to get the value of the wkrName field in the
table tblFile.
Your help would be apprieciated.

Thanks
Dave McKie
(e-mail address removed)
9/30/2004
 
Dave,

I think you need to remove the single-quote characters from this SQL Select
statement that you are building:

dbCmd.CommandText = "Select '" & strName & "' from tblFile order by '"
& strName & "' "

Like this:

dbCmd.CommandText = "Select " & strName & " from tblFile order by "
& strName

Hope this helps,

Kerry Moorman
 
Hi Kerry,

Yea...that was it. A simple solution.
Thanks for replying so quickly.

Dave
 

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

Back
Top