2 tables in one DataGrid

M

mwinne1

Hello!

I'm looking for an easy way to take 2 tables with different, but
similar, structures and combining them into one DataGrid, with a
hyperlink on each record to send you to a page depending on what table
it's from.

Is there an easy way to at least merge the two tables into one to
display the DataGrid?

Thanks for any help!

Oh yes... I'm using VB
 
Joined
Mar 22, 2006
Messages
16
Reaction score
0
Since no one has replied yet I'll start it off. My first guess would be if you had the two tables in seperate datasets and gave them the same name, then merged the datasets it might work. And then something about the MissingSchemaAction enum, or is that only for DataAdapters?
 
A

agapeton

Sorry, I know you wanted VB... you use the Merge though.

using (SqlConnection connection = new SqlConnection("data
source=servername;initial catalog=Northwind;integrated
security=SSPI;persist security info=False;packet size=4096")) {
string getEmployees = "select * from Employee";
string getNewEmployees = "select * from NewEmployee";
DataSet newNorthwind = new DataSet( );

connection.Open( );

using (SqlCommand command = new SqlCommand(getEmployees,
connection)) {
SqlDataAdapter da = new SqlDataAdapter( );
da.SelectCommand = command;
da.Fill(newNorthwind, "Employee");
}

using (SqlCommand command = new SqlCommand(getNewEmployees,
connection)) {
SqlDataAdapter da = new SqlDataAdapter( );
da.SelectCommand = command;
da.Fill(newNorthwind, "NewEmployee");
}

dataGridView1.DataSource = newNorthwind.Tables["Employee"];
dataGridView2.DataSource = newNorthwind.Tables["NewEmployee"];

newNorthwind.Tables.Add("AllEmployee");

newNorthwind.Tables["AllEmployee"].Merge(newNorthwind.Tables["Employee"]);

newNorthwind.Tables["AllEmployee"].Merge(newNorthwind.Tables["NewEmployee"]);

dataGridView3.DataSource = newNorthwind.Tables["AllEmployee"];
}

David Betz
WinFX Harmonics Blog
http://www.davidbetz.net/winfx/
 
M

mwinne1

I think it's easy enough to convert to VB. THis looks great!

However, if one table has a field called "Pizza" and another has a
field called "Hamburger", is there a way that the new datasource can
'merge' those columns into one and called it "Food"?

Thanks for the help!
 

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