-
Apr 17th, 2013, 08:58 AM
#1
Thread Starter
New Member
[RESOLVED] Insert data from database into listbox
Hi,
Basically can someone give me an example on how to insert data such as name and price from access 2007 into a list box. I ask this because i am building a POS system which will produce a receipt containing data. At the moment my forms in visual basic 2010 are linked to my database, but i have absolutely no idea on how to add data to the receipt (which is a list box).
If anyone can help me on this it would be appreciated, If you want a copy of my POS system just let me know.
-
Apr 17th, 2013, 02:42 PM
#2
Re: Insert data from database into listbox
data such as name and price
Such as? Do you want name and price or not? How are they stored in the database (columns in the same table, a single table with no other values, different tables) and in what datatype (I'm assuming Text & Currency but you know, I don't?)
At the moment my forms in visual basic 2010 are linked to my database
.... which could mean pretty much anything! the devil is yea verily in the detail!
the receipt (which is a list box)
An odd choice, particularly if you're needing to combine two or more data values to create a line. Does this mean that you will also be including items that are not drawn from the database, thereby making simple binding impossible?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Apr 17th, 2013, 03:17 PM
#3
Thread Starter
New Member
Re: Insert data from database into listbox
Such as? Do you want name and price or not? How are they stored in the database (columns in the same table, a single table with no other values, different tables) and in what datatype (I'm assuming Text & Currency but you know, I don't?)
Yes I want name and price to appear the listbox, they are two rows in the same table in my database, (Description and CostPrice are the names), and yes text and currency are the data types.
An odd choice, particularly if you're needing to combine two or more data values to create a line. Does this mean that you will also be including items that are not drawn from the database, thereby making simple binding impossible?
I chose a listbox because I can't think of another solution, (if you have a better solution please let me know?).
At the moment my forms in visual basic 2010 are linked to my database
.... which could mean pretty much anything! the devil is yea verily in the detail!
Ha sorry that was a bit vague, basically I have two forms, frmStock which is where I want to take the data from and frmReceipt which is where the listbox is, I have a button to take me from one form to the other.
I just want to know is it possible to extract data from frmStock and store it in the listbox (frmReceipt) WITHOUT using wizard.
-
Apr 17th, 2013, 03:54 PM
#4
Re: Insert data from database into listbox
Well yes is the answer. There are examples in the Codebank and the latter half of this tutorial chapter will help.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Apr 17th, 2013, 04:15 PM
#5
Re: Insert data from database into listbox
sql allows you to concatenate 2 fields into 1 field:
Code:
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Paul\Documents\REGEXP.accdb;Persist Security Info=False;")
Dim da As New OleDbDataAdapter("SELECT (field1 + "" "" + field2) AS displayField FROM testTable", conn)
Dim dt As New DataTable
da.Fill(dt)
ListBox1.DisplayMember = "displayField"
ListBox1.DataSource = dt
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 18th, 2013, 07:07 AM
#6
Thread Starter
New Member
Re: Insert data from database into listbox
Thanks for the help guys!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|