2011-10-03 13 views
5

Ho il codice seguente che ha più DataTable con risultati e ho bisogno di passare un singolo DataSet con tutti i valori DataTable.come memorizzare più DataTable in un singolo DataSet in C#?

MySqlCommand cmd = new MySqlCommand(getLikeInfo, con); 
MySqlDataAdapter da = new MySqlDataAdapter(cmd); 
DataTable dt = new DataTable(); 
da.Fill(dt); 

MySqlCommand cmd1 = new MySqlCommand(getKnowInfo, con); 
MySqlDataAdapter da1 = new MySqlDataAdapter(cmd1); 
DataTable dt1 = new DataTable(); 
da1.Fill(dt1); 

MySqlCommand cmd2 = new MySqlCommand(getHotelInfo, con); 
MySqlDataAdapter da2 = new MySqlDataAdapter(cmd2); 
DataTable dt2 = new DataTable(); 
da2.Fill(dt2); 

MySqlCommand cmd3 = new MySqlCommand(getRoomInfo, con); 
MySqlDataAdapter da3 = new MySqlDataAdapter(cmd3); 
DataTable dt3 = new DataTable(); 
da3.Fill(dt3); 

MySqlCommand cmd4 = new MySqlCommand(getFoodInfo, con); 
MySqlDataAdapter da4 = new MySqlDataAdapter(cmd4); 
DataTable dt4 = new DataTable(); 
da4.Fill(dt4); 

Come posso fare?

risposta

7
DataSet ds = new DataSet(); 
ds.Tables.Add(dt); 
ds.Tables.Add(dt1); 
... 

Se si desidera che le tabelle denominate nel DataSet è possibile creare le tabelle del DataSet

DataSet ds = new DataSet(); 
DataTable t1 = ds.Tables.Add("t1"); // Create 
DataTable t1Again = ds.Tables["t1"]; // fetch by name 

È inoltre possibile impostare la proprietà TableName delle tabelle, se si utilizza il primo approccio.

+0

Come posso identificare quelle tabelle? quando li stampo mostra tabella1, tabella2, .. – Heena

+0

@Heena, vedere risposta aggiornata –

Problemi correlati