I am new to the whole concept of "data binding". What I am trying to do seems very simple, but I don't know where to start. I have a database with an ODBC System DSN and I can connect to it with an ADODB.Connection object. I can also create an ADODB.Recordset object and traverse/manipulate the records contained in it. What I am unable to do is bind a listbox to this recordset. I know I could simply create code to traverse both the listbox and the recordset to copy recordset data to the listbox and remove listbox entries that are not in the recordset, but this is not a trivial task. Clearing the listbox and repopulating is easy enough, but doing this will reset the selected list item every time, and this is unacceptable. Any suggestions?

By the way, I am using VB 6.0

I want to add item in list box but through sql query how can i do

Hi,

Use DBListBox, Set datasource to an ADODB.recordset.. and bind

Regards
Veena

Set Rs = Nothing
Rs.open " Select * From Table Where Cond ...",Con,adOpenStatic
if Rs.Recordcount > 0 then
   rs.movefirst
  do while not rs.eof
    list1.Additem rs.fields("Field1")
    rs.movenext
  loop
end if

Thanks,

I have to create list of item which are selected in list box like
" a,b,c,d,e,f " How can I do ? it can be in a string .

I have to create list of item which are selected in list box like
" a,b,c,d,e,f " How can I do ? it can be in a string .

Hi Arun

This is Bala. Sorry I Cant Understand ur Qry. Give me the Prper.

Bye

Very aware that this thread is dated, but ran across it and thought I'd post for anyone else who comes along.

A more practical way is to use DAO instead of ADODB.

Dim rsStudID As DAO.Recordset
Set rsStudID = CurrentDb.OpenRecordset("SELECT studentID FROM applications WHERE inactive=0")
Set liststudID.Recordset = rsStudID

This will populate the liststudID List Box with source type "Table/Query" with the data very quickly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.