We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,318 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

how to add record in listbox connected in database

can anybody help me with a sample code on how to add items in listbox connected in database.
my item list are amount, description, and OR #.

3
Contributors
6
Replies
1 Day
Discussion Span
4 Months Ago
Last Updated
10
Views
Question
Answered
vonnoy
Light Poster
31 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Same as per your previous post, have a look at this discussion.

AndreRet
Industrious Poster
4,706 posts since Jan 2008
Reputation Points: 391
Solved Threads: 481
Skill Endorsements: 20

your post was using lisvtview, but im using listbox.
is listview and listbox the same in code?

vonnoy
Light Poster
31 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

use following code to add items to listbox
list1.AddItem "item1"

if you mean retrieve data from database to listbox , then use the following code

con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.Open App.Path & "\db.mdb"
rec.Open "select field_name1,field_name2 from tbl", con, 2, 3
While (rec.EOF = False)
List1.AddItem rec.Fields(0)
List2.AddItem rec.Fields(1)
rec.MoveNext
Wend
con.Close
Set con = Nothing

Note that :-
1.Replace field_name1,field_name2 with your table's fields

hope this helps you

rishif2
Junior Poster
175 posts since Dec 2012
Reputation Points: 54
Solved Threads: 34
Skill Endorsements: 3

Oops, my bad. Seems I'm human after all. I read it as listview.

If you want to add data to the listbox, as rishif2 sampled above. (Thanx rishif)

If you want to retrieve the data from listbox and add to database...

con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.Open App.Path & "\db.mdb"
rec.Open "SELECT field_name1,field_name2 FROM tbl WHERE Id ='" & idhere & "'", con, 2, 3

''If edit...
rec!field_name1 = Listbox1.Text
rec.Update

''If new record...
rec.Open "SELECT field_name1,field_name2 FROM tbl", con, 2, 3
rec!field_name1 = Listbox1.Text
rec.Update

con.Close
Set con = Nothing
AndreRet
Industrious Poster
4,706 posts since Jan 2008
Reputation Points: 391
Solved Threads: 481
Skill Endorsements: 20

its ok AndreRet
and thanks a lot guys.
you made it exactly as what i want.

vonnoy
Light Poster
31 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 4 Months Ago by AndreRet and rishif2

:) Only a pleasure.

Happy coding...

AndreRet
Industrious Poster
4,706 posts since Jan 2008
Reputation Points: 391
Solved Threads: 481
Skill Endorsements: 20

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0783 seconds using 2.67MB