index > .NET Framework Data Access and Storage > Pulling Data From Two Different Databases

Pulling Data From Two Different Databases

Hello all.
I need to pull data from two different databases in order to return some
results for a web page I am working on. How can I do this using the same sql
connection? Here's what my select statement looks like (pseudocode):
SELECT *
FROM db1.table1, db2.table1
WHERE db1.table1.UserID == db2.table1.UserID

Here is my code to connect to the database (I'm using MySQL);
string SQLQuery = "SELECT * FROM users";
OdbcConnection ODBCConnection = new OdbcConnection(connectionString);
try
{
ODBCConnection.Open(); OdbcDataAdapter ODBCAdapter = new OdbcDataAdapter(SQLQuery, ODBCConnection); DataTable dataTable = new DataTable(); ODBCAdapter.Fill(dataTable);
}
SuperStruct
Ok, in SQL Server you would only have to use the three part name database.owner.objectname (with the respective schema instead of ownername for SQl Server 2k5). But if you are really using MySQL, you are in the wrong forum, perhaps you move over to the .NET forums.

HTH, Jens Suessmeyer.

---
http://www.sqlserver2005.de
---
Jens Suessmeyer
Moved to Data Access and Storage, nothing related to SQL Server so far.

HTH, Jens Suessmeyer.

---
http://www.sqlserver2005.de
---
Jens Suessmeyer

SuperStruct -

You can acheive this by simply calling "Fill" using two different DataAdapters, with commands (and connections) pointing to two different databases. In other words, just call Fill twice.

Sahil Malik
http://blah.winsmarts.com




Author: Pro ADO.NET 2.0 // MVP C# // INETA Speaker
Sahil Malik
Once the datasets (or datatables) are filled, what do you do with them? How do you perform a SQL operation like this:
SuperStruct
reply 5

You can use google to search for other answers

 

More Articles

• i need help with passing parameters in the connectionString
• database MDI application Dataset update question using VB .NET 20...
• Active Directory+Database
• Searching Database for results
• How to do a programmatic update of table
• Execute a sql script using vb.net
• Timeout expired. the timeout expired prior to getting the connect...
• Performance question with DataReader
• ExecuteNonQuery not working within CLR Stored Procedure
• TableAdapters BaseClass
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Mysql connection
• XML Schema Help with FIX 4.4
• DataType Yes/No
• Variables in TableAdapter queries...
• ConnectionString as app.config value
• Can I open an Access database from vb .n
• Architecture
• DataGridViewCellStyle Editor
• Very strange SqlCommand TimeOut question
• Can not detach database right after back
• informix: exist a wizard to create datas
• ExecuteNonQuery not working within CLR S
• How to synchronize XML file with DataSet
• Access to SQL Database via TCP/IP
• is it good practice to pass datagrid to

Hot Articles

• How do I change the location of "|D
• Query a View
• OleDbCommand.Update method bug - paramet
• Where to store SQL server connection str
• Remoting large datasets and merging it a
• The type initializer for 'System.Data.Sq
• System.TransactionsScope and locked tabl
• Using DataSet to create database
• Merging datasets causes an exception wit
• urgent help please
• cannot get web application service
• SQL Table Lookup Methods
• T-SQL SELECT STATEMENTS
• How can I save textbox with value in the
• ADO.Net-Insert, Update, and Deleting Rec

Recommend Articles

• Internal .Net Framework Data Provider er
• How to retrieve value from UDT column wr
• default value 0
• Accessing deleted row information
• Update Statement - Syntax Problem
• Wish list for .NET 3.0 framework
• vb.net and access
• Update issue vb.net2005 express - SQLSer
• Build connection string like COM?
• Generating DataSet Relations from XML Sc
• SQLDataSource
• ExecuteNonQuery not working within CLR S
• Serializing an Object into a database Co
• Desiging Data Access
• How to perform a case insensitive filter