Bind Data to Datagrid from Multiple Sources

Posted on 2007-10-11
Last Modified: 2013-11-07
I have a Search application that performs Search and displays results in a datagrid.  The search has to be done against two different databases.   My 1st datasource is a dataset, but my 2nd datasource is an arraylist (but exactly in the same order that the datagrid expects it to be).  I am not sure how to assign the 2nd datasource to the dataadapter, and then bind the two at one time, so when the datagrid is displayed, the results from the two sources display as one.

I need ideas and examples (VB.Net).  Should I combine the results from the first datasource with the 2nd and Bind at one time or can I do a 2nd Bind after the first Bind ?  Here is my first Bind code.  

If I need to I can create the 2nd datasource as a dataset also, if that is more advisable.....    

            ''''' Create Adapter and pass the SQL string
            Dim daTPCSSearchResults As New System.Data.SqlClient.SqlDataAdapter(strBuildString, TPCSConnection)
            Dim ds As New DataSet


Question by:msyed1
    LVL 21

    Expert Comment

    I dont think it is possible to bind twice because the second bind would remove all the data from the first bind. i would suggest you to convert the results from the first datasource to a datatable and the second datasource to a datatable, add the rows from the first datatable to the second.

    or if both the datatables have a different format, just convert them both to a same format datatable
    LVL 1

    Accepted Solution

    You could bind to two seperate data grids and suppress the header on the second (sneaky sneaky)
    or conversely you can join the two using the Dataset.Merge(Dataset) command
    Fully Described here:

    Important code:
        MyCommand = New SqlDataAdapter("exec s_get_table1", MyConnection)
    DS1 = New DataSet
    MyCommand.Fill(DS1, "MyTable")
    MyCommand = New SqlDataAdapter("exec s_get_table2", MyConnection)
    DS2 = New DataSet
    MyCommand.Fill(DS2, "MyTable")
    MyDataGrid.DataSource = DS1

    for you:

     Dim daTPCSSearchResults As New System.Data.SqlClient.SqlDataAdapter(strBuildString, TPCSConnection)
                Dim ds As New DataSet
     Dim daTPCSSearchResults2 As New System.Data.SqlClient.SqlDataAdapter(strBuildString2, TPCSConnection)
                Dim ds2 As New DataSet
                dgTPCSSearchResults.DataSource = ds

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now