Add Value to DataSet Based On DataBase

C

crjunk

Hi,

I'm pulling data from 3 different databases into 1 DataSet. Is there a
way that I can insert a new field into the DataSet and add a value
(such as "MSBA", "AFCA", "AFNAT", etc...) to each record based on the
database that the record came from?

Here is how I pulling data into my DataSet right now.

Thanks,
crjunk

Private Sub BindData()

GetConnectionString()

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

Dim tmpID As String = Request.QueryString("ID")

'Ensure that the ID is 4 charactes long
While Len(Trim(tmpID)) < 4 And Len(Trim(tmpID)) > 0
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_amfnat As New OdbcCommand(strSQL,
amfnat_OdbcConnection)
Dim myCommand_msba As New OdbcCommand(strSQL,
msba_OdbcConnection)
Dim myCommand_bcam As New OdbcCommand(strSQL,
bcam_OdbcConnection)
Dim myCommand_afca As New OdbcCommand(strSQL,
afca_OdbcConnection)

'Create the DataAdapter for AMFNAT and Populate the DataSet
myDA.SelectCommand = myCommand_amfnat
myDA.Fill(myDS)

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

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

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

'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()

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

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

myDA.Dispose()
myDA = Nothing

myCommand_amfnat.Dispose()
myCommand_amfnat = Nothing

myCommand_msba.Dispose()
myCommand_msba = Nothing

myCommand_bcam.Dispose()
myCommand_bcam = Nothing

myCommand_afca.Dispose()
myCommand_afca = Nothing

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top