db connection for single command

Oct 16, 2008 at 7:08 AM
hi i hav different database i have to link all database table in a single query. how many db-connection can i use in a single command.
Oct 16, 2008 at 10:02 AM
Each DbCommand has only one DbConnection.  Are you actually asking if you need a Database object for each tables you would be querying or if you can use a single Database object to execute such query?  Anyway, this works fine for me.

Connection string in DataAccess Application Block


add name="AdWorks2" connectionString="Database=AdWorks2;Server=(local);Integrated Security=SSPI" providerName="System.Data.SqlClient" />

C# code
Database db = DatabaseFactory.CreateDatabase("AdWorks2");
string sqlCommand= SELECT ADV1.*
FROM OPENDATASOURCE('SQLOLEDB','Server=(local);Integrated Security=SSPI').AdWorks.dbo.Employee ADV1, 
AdWorks2.dbo.Employee ADV2

DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);
DbConnection connection = db.CreateConnection();
DataSet ds = db.ExecuteDataSet(dbCommand);
dataGridView1.DataSource = ds.Tables[0];