Hi!!
In my form, i have a listbox which contains the column data of a table from the database. I retrived the data from database (wrote code into constructor) to listbox and it is working well.
Now i have problem here:
based on user selected item of the list box, i want to retrieve the concerned data from the database and should be place into textboxes.
Give me some solutions.
Darma
Loading
VulpesPosted Apr 26, 2012, 5:17 PM
SELECT table1.projectid AS projectid, table2.name AS name, table3.time AS time from table1, table2, table3 WHERE table1.projectid = table2.projectid AND table1.projectid = table3.projectid
You should then be able to bind the ListBox to the projectid column as before.
When the SelectedIndex of the ListBox changes, you can then assign the name and time columns in the same row of the DataTable as the projectid to your TextBoxes.
darma tejaPosted Apr 26, 2012, 4:38 PM
Thanks!!
Give me some more idea to do. For you convenience i am giving u an example.
I have a table like this
1st table:
projectid
1
2
3
4
5
2nd table:
name projectid
xyz 1
abc 2
def 3
3rd table:
time projectid
1 1
2 2
1 3
I retrieved the Projectid data from Database and stored into listbox.
Whenever I select the an item in listbox (for example I selected projecteId 2)
On my windows form shows as follows:
Name abc
Time 2
VulpesPosted Apr 26, 2012, 11:15 AM
darma tejaPosted Apr 26, 2012, 10:51 AM
Thanks for ur reply.
No,
based on the selected value in the listbox, i wanted to retrieve the data from other tables (not from the same table which i got listbox values).
Darma
VulpesPosted Apr 26, 2012, 9:31 AM
If you do, then I'd retrieve the whole row and not just a single column from the database in the first place.
The index of the selected column in the listbox should then correspond with the index of the row in the DataTable.Rows collection from which that column has been derived.