Dear all,
I am relatively new to vb.net/SQL Server and am struggling to find a way of executing a select statement which will allow me to access tables located in different databases. I am under the impression that a connection string can only be referenced to a single database at any one time. The code I typically use to read from a table only allows for one connection string and is as follows:
How would I achieve the above if Table_A was to reside in Database_A and Table_B was to reside in Database_B?
Thank you in advance for any suggestions.
MJC
I am relatively new to vb.net/SQL Server and am struggling to find a way of executing a select statement which will allow me to access tables located in different databases. I am under the impression that a connection string can only be referenced to a single database at any one time. The code I typically use to read from a table only allows for one connection string and is as follows:
VB.NET:
'SQLCon -> Connection to Database containing both tables.
Dim iSQL As String = "SELECT Table_A.My_Id, Table_A.MyValue, Table_B.MyValue FROM Table_A INNER JOIN Table_B ON Table_A.My_Id = Table_B.My_Id"
If SQLCon.State <> ConnectionState.Open Then SQLCon.Open()
SQLCmd = New SqlCommand(iSQL, SQLCon)
Dim R As SqlDataReader = SQLCmd.ExecuteReader
While R.Read
'Do Something...
End While
How would I achieve the above if Table_A was to reside in Database_A and Table_B was to reside in Database_B?
Thank you in advance for any suggestions.
MJC