How to retrieve multiple records from a access database????????

N

Neil

Hello everyone,
I am making a program at the moment, and need HELP!!!. I'll start
with the database, my field's r:
fldSku - which a 6 digit number, no more no less (145682)
fldDescription - which is the description of a clothing
fldLabel - Which is the band name of the clothing
and fldPrice. k, what i need to do is, when i search for a SKU (which
might have duplicates) in the db, i want it to return it to a datagrid
on the form, and plus i don't know how to retrieve multiple records
from a db, which will be the same SKU, then put them into a datagrid.

Any help is greatly appreciated.
Thanks.

Neil
(e-mail address removed)
 
K

Ken Tucker [MVP]

Hi,

Put a listbox named listbox1 and a datagrid named datagrid1 on a
windows form. Here is a simple example.


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strConn As String
Dim conn As OleDb.OleDbConnection
Dim daCustomer As OleDb.OleDbDataAdapter
Dim ds As DataSet

ds = New DataSet()
strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
strConn &= "Data Source = Northwind.mdb;"

conn = New OleDb.OleDbConnection(strConn)

daCustomer = New OleDb.OleDbDataAdapter("Select * from Customers",
conn)

ds = New DataSet

daCustomer.Fill(ds, "Customers")

ListBox1.DataSource = ds.Tables("Customers")
ListBox1.DisplayMember = "CustomerID"


End Sub


Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim drv As DataRowView = ListBox1.SelectedValue
Dim stritem As String = drv.Item("CustomerID").ToString
Trace.WriteLine(stritem)

Dim strConn As String
Dim conn As OleDb.OleDbConnection
Dim daOrder As OleDb.OleDbDataAdapter
Dim ds As DataSet

ds = New DataSet
strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
strConn &= "Data Source = Northwind.mdb;"

conn = New OleDb.OleDbConnection(strConn)

daOrder = New OleDb.OleDbDataAdapter("Select * from Orders where
CustomerID = '" & stritem & "'", conn)
daOrder.Fill(ds, "Orders")
DataGrid1.DataSource = ds.Tables("Orders")
End Sub

Ken
 

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

Top