473,554 Members | 3,144 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populate a DataGrid from Multiple Databases - Order Problem

I have 4 different databases that I'm having to pull data from in order
to populate a datagrid. I am able to do this, but my problem is that
because I'm pulling the data from 4 different databases, the data is
ordered alphabetically but is grouped by database.

Here is an example of what is happening to the data in the datgrid with
the code that I have now.
DB1 Apple
DB1 Bird
DB1 Cake
DB2 Airplane
DB2 Boat
DB2 Circle
DB3 Amazing
DB3 Blue
etc.....

I want ALL the data in the datagrid ordered alphabetically, reguardless
of which database it is from.

This is the code that I'm using to bind data to my datagrid. Can I add
something to my code to order the data correctly or do I need to go
about this another way?

Private Sub BindData()

GetConnectionSt ring()

Dim strSQL As String = "SELECT DISTINCT DB_PDESCR, DB_PPROD
FROM PUB.PCFPOLCY "
Dim strWhere As String = ""
Dim strOrderBy As String = ""

Dim tmpID As String = Request.QuerySt ring("ID")

'Ensure that the ID is 4 charactes long
While Len(Trim(tmpID) ) < 4
tmpID = "0" & Trim(tmpID)
End While

strWhere = " WHERE DB_PPROD = '" & Trim(tmpID) & "'"
strOrderBy = " ORDER BY DB_PDESCR"
strSQL = strSQL & strWhere & strOrderBy

Dim myDA As New OdbcDataAdapter
Dim myDS As New DataSet
Dim myCommand_amfna t As New OdbcCommand(str SQL,
amfnat_OdbcConn ection)
Dim myCommand_msba As New OdbcCommand(str SQL,
msba_OdbcConnec tion)
Dim myCommand_bcam As New OdbcCommand(str SQL,
bcam_OdbcConnec tion)
Dim myCommand_afca As New OdbcCommand(str SQL,
afca_OdbcConnec tion)

'Create the DataAdapter for AMFNAT and Populate the DataSet
myDA.SelectComm and = myCommand_amfna t
myDA.Fill(myDS)

'Create the DataAdapter for MSBA and Populate the DataSet
myDA.SelectComm and = myCommand_msba
myDA.Fill(myDS)

'Create the DataAdapter for BCAM and Populate the DataSet
myDA.SelectComm and = myCommand_bcam
myDA.Fill(myDS)

'Create the DataAdapter for AFCA and Populate the DataSet
myDA.SelectComm and = myCommand_afca
myDA.Fill(myDS)

'Set the datagrid's datasource to the dataset and databind
dgAllCompanies. DataSource = myDS
dgAllCompanies. DataBind()

'Display error message if there are no records.
If myDS.Tables(0). Rows.Count = 0 Then
lblNoResults.Vi sible = True
dgAllCompanies. Visible = False
Else
lblNoResults.Vi sible = False
dgAllCompanies. Visible = True
End If

''*** Clean Up
myDS.Dispose()
myDS = Nothing

myDA.Dispose()
myDA = Nothing

myCommand_amfna t.Dispose()
myCommand_amfna t = Nothing

myCommand_msba. Dispose()
myCommand_msba = Nothing

myCommand_bcam. Dispose()
myCommand_bcam = Nothing

myCommand_afca. Dispose()
myCommand_afca = Nothing

End Sub
Thanks for taking the time to look at my problem!
Crjunk

Nov 19 '05 #1
3 2076
you can create your own custom class and implement icomparable interface
, then use arraylist to bind data to datagrid
crjunk wrote:
I have 4 different databases that I'm having to pull data from in order
to populate a datagrid. I am able to do this, but my problem is that
because I'm pulling the data from 4 different databases, the data is
ordered alphabetically but is grouped by database.

Here is an example of what is happening to the data in the datgrid with
the code that I have now.
DB1 Apple
DB1 Bird
DB1 Cake
DB2 Airplane
DB2 Boat
DB2 Circle
DB3 Amazing
DB3 Blue
etc.....

I want ALL the data in the datagrid ordered alphabetically, reguardless
of which database it is from.

This is the code that I'm using to bind data to my datagrid. Can I add
something to my code to order the data correctly or do I need to go
about this another way?

Private Sub BindData()

GetConnectionSt ring()

Dim strSQL As String = "SELECT DISTINCT DB_PDESCR, DB_PPROD
FROM PUB.PCFPOLCY "
Dim strWhere As String = ""
Dim strOrderBy As String = ""

Dim tmpID As String = Request.QuerySt ring("ID")

'Ensure that the ID is 4 charactes long
While Len(Trim(tmpID) ) < 4
tmpID = "0" & Trim(tmpID)
End While

strWhere = " WHERE DB_PPROD = '" & Trim(tmpID) & "'"
strOrderBy = " ORDER BY DB_PDESCR"
strSQL = strSQL & strWhere & strOrderBy

Dim myDA As New OdbcDataAdapter
Dim myDS As New DataSet
Dim myCommand_amfna t As New OdbcCommand(str SQL,
amfnat_OdbcConn ection)
Dim myCommand_msba As New OdbcCommand(str SQL,
msba_OdbcConnec tion)
Dim myCommand_bcam As New OdbcCommand(str SQL,
bcam_OdbcConnec tion)
Dim myCommand_afca As New OdbcCommand(str SQL,
afca_OdbcConnec tion)

'Create the DataAdapter for AMFNAT and Populate the DataSet
myDA.SelectComm and = myCommand_amfna t
myDA.Fill(myDS)

'Create the DataAdapter for MSBA and Populate the DataSet
myDA.SelectComm and = myCommand_msba
myDA.Fill(myDS)

'Create the DataAdapter for BCAM and Populate the DataSet
myDA.SelectComm and = myCommand_bcam
myDA.Fill(myDS)

'Create the DataAdapter for AFCA and Populate the DataSet
myDA.SelectComm and = myCommand_afca
myDA.Fill(myDS)

'Set the datagrid's datasource to the dataset and databind
dgAllCompanies. DataSource = myDS
dgAllCompanies. DataBind()

'Display error message if there are no records.
If myDS.Tables(0). Rows.Count = 0 Then
lblNoResults.Vi sible = True
dgAllCompanies. Visible = False
Else
lblNoResults.Vi sible = False
dgAllCompanies. Visible = True
End If

''*** Clean Up
myDS.Dispose()
myDS = Nothing

myDA.Dispose()
myDA = Nothing

myCommand_amfna t.Dispose()
myCommand_amfna t = Nothing

myCommand_msba. Dispose()
myCommand_msba = Nothing

myCommand_bcam. Dispose()
myCommand_bcam = Nothing

myCommand_afca. Dispose()
myCommand_afca = Nothing

End Sub
Thanks for taking the time to look at my problem!
Crjunk

Nov 19 '05 #2
If you can put whole data from four databases into one
datatable, you can use dataview's (=
datatable.Defau ltView) Sort property to sort all data.
Then you bind datagrid with the sorted dataview. It shows
alphabetically ordered data.

HTH

Elton Wang
el********@hotm ail.com
-----Original Message-----
I have 4 different databases that I'm having to pull data from in orderto populate a datagrid. I am able to do this, but my problem is thatbecause I'm pulling the data from 4 different databases, the data isordered alphabetically but is grouped by database.

Here is an example of what is happening to the data in the datgrid withthe code that I have now.
DB1 Apple
DB1 Bird
DB1 Cake
DB2 Airplane
DB2 Boat
DB2 Circle
DB3 Amazing
DB3 Blue
etc.....

I want ALL the data in the datagrid ordered alphabetically, reguardlessof which database it is from.

This is the code that I'm using to bind data to my datagrid. Can I addsomething to my code to order the data correctly or do I need to goabout this another way?

Private Sub BindData()

GetConnectionSt ring()

Dim strSQL As String = "SELECT DISTINCT DB_PDESCR, DB_PPRODFROM PUB.PCFPOLCY "
Dim strWhere As String = ""
Dim strOrderBy As String = ""

Dim tmpID As String = Request.QuerySt ring("ID")

'Ensure that the ID is 4 charactes long
While Len(Trim(tmpID) ) < 4
tmpID = "0" & Trim(tmpID)
End While

strWhere = " WHERE DB_PPROD = '" & Trim(tmpID) & "'" strOrderBy = " ORDER BY DB_PDESCR"
strSQL = strSQL & strWhere & strOrderBy

Dim myDA As New OdbcDataAdapter
Dim myDS As New DataSet
Dim myCommand_amfna t As New OdbcCommand(str SQL,
amfnat_OdbcCon nection)
Dim myCommand_msba As New OdbcCommand(str SQL,
msba_OdbcConne ction)
Dim myCommand_bcam As New OdbcCommand(str SQL,
bcam_OdbcConne ction)
Dim myCommand_afca As New OdbcCommand(str SQL,
afca_OdbcConne ction)

'Create the DataAdapter for AMFNAT and Populate the DataSet myDA.SelectComm and = myCommand_amfna t
myDA.Fill(myDS)

'Create the DataAdapter for MSBA and Populate the DataSet myDA.SelectComm and = myCommand_msba
myDA.Fill(myDS)

'Create the DataAdapter for BCAM and Populate the DataSet myDA.SelectComm and = myCommand_bcam
myDA.Fill(myDS)

'Create the DataAdapter for AFCA and Populate the DataSet myDA.SelectComm and = myCommand_afca
myDA.Fill(myDS)

'Set the datagrid's datasource to the dataset and databind dgAllCompanies. DataSource = myDS
dgAllCompanies. DataBind()

'Display error message if there are no records.
If myDS.Tables(0). Rows.Count = 0 Then
lblNoResults.Vi sible = True
dgAllCompanies. Visible = False
Else
lblNoResults.Vi sible = False
dgAllCompanies. Visible = True
End If

''*** Clean Up
myDS.Dispose()
myDS = Nothing

myDA.Dispose()
myDA = Nothing

myCommand_amfna t.Dispose()
myCommand_amfna t = Nothing

myCommand_msba. Dispose()
myCommand_msba = Nothing

myCommand_bcam. Dispose()
myCommand_bcam = Nothing

myCommand_afca. Dispose()
myCommand_afca = Nothing

End Sub
Thanks for taking the time to look at my problem!
Crjunk

.

Nov 19 '05 #3
Thanks Elton and ashish. I figured out that I could use a DataView
before I read your message after doing a bunch of searching. Thanks
for your help. Here is what I added/changed in my code.

'Create a DataView so that I can order the data before the
DataGrid is populated.
'Otherwise the data will be in alphabetical order in DataGrid,
but grouped by DataBase.
Dim dvArrange As DataView = myDS.Tables(0). DefaultView
dvArrange.Sort = "DB_PDESCR"

'Set the datagrid's datasource to the DataView and bind data.
dgAllCompanies. DataSource = dvArrange
dgAllCompanies. DataBind()

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2019
by: Sergio | last post by:
Hi everybody, I have the following scenario. Several computers with shared disk in a LAN. Each of these computer has a MySQL server that serves several databases. I have several clients that communicate with a Java process that I have in each computer to answer queries for a given database (it connects to the MySQL server). I also have a...
1
18239
by: Brian | last post by:
I have a dataset containing 2 tables. I need to fill a datagrid using data from both of these. If I could create a SQL Statement to fill the datagrid, it would look like this: SELECT fields.fieldname, fieldvalues.value FROM fields, fieldvalues I am having trouble finding documentation explaining how to populate
5
2363
by: sdbranum | last post by:
I have been using Visual C#.NET to code a large project having many data adapters, data sets, datagrids, multiple forms with tab pages, each containing various controls (mostly label, text boxes, check boxes, date pickers, combo boxes and datagrids). I have been coding alone on this project for about a year, and I have experienced many...
3
2685
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to populate multiple webpages containing customer information. There isn't a one-to-one correlation between the stored procedure and a webpage. In other...
9
5041
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ******************************************************************************* <asp:DataGrid visible="False" border=1
1
2030
by: Simon Harris | last post by:
Hi All, I wish to populate more than one datagrid from the same OleDBCommand. The code I have is: Dim objCmd As New OleDbCommand(strSql, objConn) Then... Me.dgTariffHolidayHomesBand1.DataSource = objCmd.ExecuteReader()
2
2479
by: gn | last post by:
I am able to populate a datagrid from an XML variable using the following: Try Dim ds As New DataSet ds.ReadXml(New StringReader(HttpContext.Current.Application("var").ToString)) dataMeet.DataSource = ds dataMeet.DataBind() Catch ex As Exception
1
1399
by: Raj | last post by:
Hi I am trying to populate datagrid with a query which has multiple tables on it. It loads data fine but when I try to apply tablestylegrid and columnstyles its not taking it. Can anybody help....? Thanks Raj
0
1329
by: rn5a | last post by:
A DataGrid control displays records from a SQL Server 2005 DB table. The AllowSorting property of the DataGrid has been set to True & the SortExpressions of the BoundColumns have been set to the different columns so that users can sort the DataGrid by clicking the headers in the DataGrid. The DataGrid can be sorted using all the headers in the...
0
7594
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7792
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7556
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7885
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5430
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5151
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2014
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.