Surka
New member
- Joined
- Dec 31, 2013
- Messages
- 2
- Programming Experience
- 3-5
Access DB tables and fields:
With a 1 to Many Relationship, by ID_User on both tables.
Example, of table and relationship:
table Devices:
ID_User--Device---WarrantyEnd
2----------Laptop---2016
2----------Monitor--2016
3----------Laptop---2016
table Users:
ID_User--UserName
2----------AAA
3----------BBB
I need to fill a listView list, and show 3 columns: UserName, Device and WarrantyEnd.
Here is the Query:
Code:
As you can see, there is a relationship using RIGHT JOIN, by ID_User from both tables.
Using that query, I am trying to fill the listView with the following code:
Code:
But debug, tells me theres an error on: DataReader = cmd.ExecuteReader(): No value given for one or more required parameters.
If I use an easier query it works: strSQL = "SELECT * FROM Devices"
Am I missing something on the query?
Thanks.
- Users: ID_User, UserName
- Devices: ID_User, Device, WarrantyEnd
With a 1 to Many Relationship, by ID_User on both tables.
Example, of table and relationship:
table Devices:
ID_User--Device---WarrantyEnd
2----------Laptop---2016
2----------Monitor--2016
3----------Laptop---2016
table Users:
ID_User--UserName
2----------AAA
3----------BBB
I need to fill a listView list, and show 3 columns: UserName, Device and WarrantyEnd.
Here is the Query:
Code:
VB.NET:
SELECT Users.UserName, Devices.Device, Devices.WarrantyEnd
FROM Users RIGHT JOIN Devices ON Users.ID_User = Devices.ID_User
As you can see, there is a relationship using RIGHT JOIN, by ID_User from both tables.
Using that query, I am trying to fill the listView with the following code:
Code:
VB.NET:
'QUERY
strSQL = "SELECT Users.UserName, Devices.Device, Devices.WarrantyEnd FROM Users RIGHT JOIN Devices ON Users.ID_User = Devices.ID_User"
cmd.Connection = connection
cmd.CommandText = strSQL
DataReader = cmd.ExecuteReader()
'While reading, it fills listView. Last command adds all the newItem read to the listView
Do While DataReader.Read()
Dim newItem As New ListViewItem(DataReader.Item(1).ToString)
newItem .SubItems.Add(DataReader.Item(0).ToString)
mainForm.listView.Items.Add(newItem )
Loop
DataReader.Close()
But debug, tells me theres an error on: DataReader = cmd.ExecuteReader(): No value given for one or more required parameters.
If I use an easier query it works: strSQL = "SELECT * FROM Devices"
Am I missing something on the query?
Thanks.