• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

Bind Data to Datagrid from Multiple Sources

Hello,
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
            daTPCSSearchResults.Fill(ds)

            dgTPCSSearchResults.DataBind()


0
msyed1
Asked:
msyed1
1 Solution
 
surajgupthaCommented:
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
0
 
MgreenwayCommented:
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:
http://aspalliance.com/148

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")
DS1.merge(DS2)
MyDataGrid.DataSource = DS1
MyDataGrid.DataBind()


for you:

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now