none
(Sumber: milis SQL Server) query utk mengambil record dari database yang berbeda menggunakan vb .net 2010 RRS feed

  • Pertanyaan

  • Dear all,
    Mohon pencerahannya, sy punya masalah ketika ingin mengambil record dari sql server dengan ketentuan data diambil dari database yang berbeda. setelah sy googling berikut syntax yg sy dapatkan :

    SELECT Database1.TableA.ColumnA1 AS dA1,
    Database1.TableA.ColumnA2 AS dA2,
    Database2.TableB.ColumnB1 AS dB1,
    Database2.TableB.ColumnB2 AS dB2
    FROM Database1.TableA
    INNER JOIN
    Database2.TableB ON
    Database1.TableA.ColumnA3 = Database2.TableB.ColumnB3

    sy biasa menggunakan ADO .Net dg syntax :
    Imports System.Data
    Imports System.Data.SqlClient
    Public ConDB As New SqlConnection
    Public Command As New SqlCommand
    Public ObjDtReader As SqlDataReader
    Public ConStr As String
    Public VarField1 As String
    Public Sub OpenDatabase()
    ConStr = "Server=PC1;Database=database;user id=sa;password=sa;"
    ConDB.ConnectionString = ConStr
    Try
    If ConDB.State <> ConnectionState.Closed Then
    ConDB.Close()
    ConDB.Open()
    Else
    ConDB.Open()
    End If
    Catch ex As Exception
    MsgBox("Sorry Can not open database! ")
    End Try
    End Sub
    OpenDatabase()
    Command.Connection = ConDB
    Command.CommandType = CommandType.Text
    Command.CommandText = "SELECT FIELD1 FROM TABLE1"
    ObjDtReader = Command.ExecuteReader
    If ObjDtReader.Read = True Then
    VarField1 = ObjDtReader("FIELD1")
    End If
    ObjDtReader.Close()
    ConDB.Close()

    Permasalahannya bagaimana utk mengimplementasikan sample query tsb kedalam vb .net 2010??
    Terimakasih atas bantuannya sebelumnya.


    Agnes Sannie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Kamis, 27 September 2012 08.39
    Moderator

Jawaban