single DataSet having multiple DataTables from multiple databases
-
It is possible to have a single DataSet having multiple DataTables from multiple databases. If so can you just tell me how ?
-
It is possible to have a single DataSet having multiple DataTables from multiple databases. If so can you just tell me how ?
Yes it is.
var ds = new DataSet();
using (var connection = new SqlConnection("..."))
{
var da = new SqlDataAdapter("SELECT ...", connection);
da.SelectCommand.Parameters.AddWithValue(...);
da.Fill(ds, "FirstTable");
}using (var connection = new OleDbConnection("..."))
{
var da = new OleDbDataAdapter("SELECT ...", connection);
da.SelectCommand.Parameters.AddWithValue(...);
da.Fill(ds, "SecondTable");
}If one of your queries returns multiple result-sets, you might need to use
TableMappings
to specify the table names: DataAdapter DataTable and DataColumn Mappings | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
It is possible to have a single DataSet having multiple DataTables from multiple databases. If so can you just tell me how ?
Many years ago I experimented with SQL Server returning multiple tables from a single stored procedure. The performance was dramatically slower then return multiple single tables from individual stored procs. Performance may have changed in recent versions.
Never underestimate the power of human stupidity RAH
-
Yes it is.
var ds = new DataSet();
using (var connection = new SqlConnection("..."))
{
var da = new SqlDataAdapter("SELECT ...", connection);
da.SelectCommand.Parameters.AddWithValue(...);
da.Fill(ds, "FirstTable");
}using (var connection = new OleDbConnection("..."))
{
var da = new OleDbDataAdapter("SELECT ...", connection);
da.SelectCommand.Parameters.AddWithValue(...);
da.Fill(ds, "SecondTable");
}If one of your queries returns multiple result-sets, you might need to use
TableMappings
to specify the table names: DataAdapter DataTable and DataColumn Mappings | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thank you for your replay .... however, I am looking different databases from the same provider
-
Thank you for your replay .... however, I am looking different databases from the same provider
So load data from different databases from the same provider then. What's the problem?
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Many years ago I experimented with SQL Server returning multiple tables from a single stored procedure. The performance was dramatically slower then return multiple single tables from individual stored procs. Performance may have changed in recent versions.
Never underestimate the power of human stupidity RAH