By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,083 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

Using a Listview to Populate a combo box

P: n/a
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
da*********@yahoo.com
9/30/2004
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"Dave McKie" wrote:
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.
SNIP
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
da*********@yahoo.com
9/30/2004

Nov 21 '05 #2

P: n/a

Hi Kerry,

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

Dave
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.