Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Tables, same fields, can they be bound to 1 datagrid?

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
Basically that is it. I have two tables, with the same fields, and I want them to appear in the same datagrid.

Ex.
Table1(Spray)
Product, Quant, Price
xxx, 1, 1.55
zzz, 3, 3.66

Table2(Mounting)
Product, Quant, Price
ttt, 2, 12.50
mmm, 1, 5.00
 
You'll need to graft them together first.
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
k, so I have 2 datatables, how do I graft them?
 
qwert, look up "new datarow .net" on google. There are a host of examples out there for this type of operation.

You just iterate one datatable, and add the rows from it to the other as you go.
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
Oh, sorry for the confusion. I was hoping there would be an easier, less consuming solution.

So, I will go with my original code:
Code:
For Each objRow In dataTable2.Rows
 dataTable1.Rows.Add(objRow)
Next
 
There is assuming you're using a DB. Create a Union SQL. Basically, get your two pieces of SQL put then in one view or stored proc and stick the word UNION between them.

Craig
 
Nope, not SQL. I did it just as mentioned above. Thanks tho.
 
Also, I have had much success using a single stored procedure with multiple SELECT statements that I loop through passing dynamic values, clearing the parameters each time, then re-running as necessary. This allows me to continue to populate the same datagrid on the fly from any source (even multiple tables). There are plenty of easier ways, but this gives me a great deal of control including adding in rows to create subheaders.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top