Data from Two Databases

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Helen Trim

    Data from Two Databases

    I am programming in visual basic dot net and I need a dataset built from
    tables in two different databases. Is it possible to create connections to
    both and then create a SQL command to open the dataset?

    TIA

    --
    Helen
  • Cor Ligthert [MVP]

    #2
    Re: Data from Two Databases

    Helen,

    You have to create one dataset, with two connections, two datatadapters and
    two fills.

    You can do that using the designer.

    In code it is roughly typed

    \\\
    dim ds as new dataset
    dim conn1 as new sqlconnection(c onnectionstring 1)
    dim conn2 as new sqlconnection(c onnectionstring 2)
    dim da1 as new sqldataadapter( sqlstring,conn1 )
    dim da2 as new sqldataadapter( sqlstring,conn2 )
    da1.fill(ds)
    da2.fill(ds)
    ///
    That is all without a try block. (The dataadapter takes care of the open and
    close itself).

    I hope this helps,

    Cor


    Comment

    Working...