i'm new to vb.net and i cant figure out how to solve this problem
any help would be greatly appreciated
how can i show data into list view if the data is located in different tables.
here few of my code,
Public strConn As String = "C:\*********.mdb"
Public cn As New OleDb.OleDbConnection
Private Sub open_connection()
close_connection()
cn.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source= " & strConn
If cn.State = ConnectionState.Closed Then
cn.Open()
End If
End Sub
Private Sub load_data()
open_connection()
Dim a As Integer
Dim da As New OleDb.OleDbDataAdapter("Select * from tblstock", cn)
Dim ds As New DataSet
da.Fill(ds)

lststock.Items.Clear()

For a = 0 To ds.Tables(0).Rows.Count - 1
lststock.Items.Add(ds.Tables(0).Rows(a).Item("Brand_Name"))
lststock.Items(a).SubItems.Add(ds.Tables(0).Rows(a).Item("Generic_Name"))
Next
close_connection()
End Sub
the problem is i dont know how to display to the list view the other data that is located in another table.

Recommended Answers

All 2 Replies

For a = 0 To ds.Tables(0).Rows.Count - 1
lststock.Items.Add(ds.Tables(0).Rows(a).Item("Brand_Name"))
lststock.Items(a).SubItems.Add(ds.Tables(0).Rows(a).Item("Generic_Name"))
Next
close_connection()

From what I can see you are only adding information from one table in the code right now (Tables(0)), if I am understanding correctly. If you just want to add the data from another table, you should be able to just add another loop like this one, but replace Tables(0) with whichever table you are trying to add.

yes your right, im only adding information from a single table. But for example i would like to add to my listview another information from a different table like the first table is named tblstock and the other information that i'll be adding will be coming from tblstock2 and the column name is "Net_Sale" how am suppose to start writing the code. thanks.

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.