English:
Considering that your databases are both on the same server/instance, yes, you can get fields from two or more databases.
Remember:
-for this example you are using MyODBC 3.51 like me (MySQL 32bits, so, MyODBC 32bits);
-your data source name is "store" and was properly set up;
-Reference: Microsoft ActiveX Data Objects 2.5 library
Português:
SELECT em dois bancos (desde que estejam no mesmo servidor e instância do MySQL)
Considere:
-Para este exemplo, estou usando o MyODBC 3.51 (MySQL de 32 bits, ODBC de 32bits)
-Referenciar: Microsoft ActiveX Data Objects 2.5 library
__________________________
Raw/didactic code (please, read this twice)
Private Sub getItemDescription(code as string)
Dim sql As String
sql = "SELECT dbStore.itens.description from dbCentral.itens, dbStore.itens " _
+ "WHERE dbStore.itens.BarCode = dbCentral.itens.BarCode " _
+ "AND dbStore.itens.BarCode = '" & code & "';"
Dim con As ADODB.Connection
Dim table As New ADODB.Recordset
Set con = New ADODB.Connection
con.Open "Provider=MSDASQL.1;Persist Security Info=False;" _
+ "Data Source=store; Database=dbStore"
table.Open sql, con
If Not (table.EOF) Then
MsgBox table!description
End If
con.Close
set con = Nothing
End Sub
'-------------------------------------
If you are not using DSN (but MyODBC):
(pt-BR: Se não estiver usando Data Source Name, somente MyODBC)
Private Sub getItemDescription(code as string)
Dim sql As String
sql = "SELECT dbStore.itens.description from dbCentral.itens, dbStore.itens " _
+ "WHERE dbStore.itens.BarCode = dbCentral.itens.BarCode " _
+ "AND dbStore.itens.BarCode = '" & code & "';"
Dim cn As ADODB.Connection
Dim mySQLConString As String
Dim tbl As New ADODB.Recordset
mySQLConString = "DRIVER={MySQL ODBC 3.51 Driver};" _
+ "SERVER=localhost;user=root;password=1234;" _
+ "Persist Security Info=False;Encrypt=yes"
Set cn = New ADODB.Connection
cn.Open (mySQLConString)
tbl.Open sql, cn
If Not (tbl.EOF) Then
MsgBox tbl!description
End If
cn.Close
Set cn = Nothing
End Sub
__________________________
Question: Why VB6?
Answer: just legacy code
Considering that your databases are both on the same server/instance, yes, you can get fields from two or more databases.
Remember:
-for this example you are using MyODBC 3.51 like me (MySQL 32bits, so, MyODBC 32bits);
-your data source name is "store" and was properly set up;
-Reference: Microsoft ActiveX Data Objects 2.5 library
Português:
SELECT em dois bancos (desde que estejam no mesmo servidor e instância do MySQL)
Considere:
-Para este exemplo, estou usando o MyODBC 3.51 (MySQL de 32 bits, ODBC de 32bits)
-Referenciar: Microsoft ActiveX Data Objects 2.5 library
__________________________
Raw/didactic code (please, read this twice)
Private Sub getItemDescription(code as string)
Dim sql As String
sql = "SELECT dbStore.itens.description from dbCentral.itens, dbStore.itens " _
+ "WHERE dbStore.itens.BarCode = dbCentral.itens.BarCode " _
+ "AND dbStore.itens.BarCode = '" & code & "';"
Dim con As ADODB.Connection
Dim table As New ADODB.Recordset
Set con = New ADODB.Connection
con.Open "Provider=MSDASQL.1;Persist Security Info=False;" _
+ "Data Source=store; Database=dbStore"
table.Open sql, con
If Not (table.EOF) Then
MsgBox table!description
End If
con.Close
set con = Nothing
End Sub
'-------------------------------------
If you are not using DSN (but MyODBC):
(pt-BR: Se não estiver usando Data Source Name, somente MyODBC)
Private Sub getItemDescription(code as string)
Dim sql As String
sql = "SELECT dbStore.itens.description from dbCentral.itens, dbStore.itens " _
+ "WHERE dbStore.itens.BarCode = dbCentral.itens.BarCode " _
+ "AND dbStore.itens.BarCode = '" & code & "';"
Dim cn As ADODB.Connection
Dim mySQLConString As String
Dim tbl As New ADODB.Recordset
mySQLConString = "DRIVER={MySQL ODBC 3.51 Driver};" _
+ "SERVER=localhost;user=root;password=1234;" _
+ "Persist Security Info=False;Encrypt=yes"
Set cn = New ADODB.Connection
cn.Open (mySQLConString)
tbl.Open sql, cn
If Not (tbl.EOF) Then
MsgBox tbl!description
End If
cn.Close
Set cn = Nothing
End Sub
__________________________
Question: Why VB6?
Answer: just legacy code
Comentários
Postar um comentário