Solved

Datatable not populating correctly

Posted on 2010-08-31
2
367 Views
Last Modified: 2012-05-10
Hello,

Below is code I modified from code I had used to to create a graph. I have modified to work with other code that I developed to export a graph and it's underlying dataset to an excel dataset.  as part of my testing, I added a datagridview to the calling form in order to verify that I was getting the correct values.  After executing the code, I see, that the same I am getting duplicate values.  For example for two graph object, I am getting the same results.  I'm not sure what the problem is.
Private Function CreateGraphTable(ByVal intDatasetGroupId) As DataTable
        Dim graphs As New List(Of GraphReport)
        Dim dset As New DataSet("MyDataSet")
        Dim strTitleName As String = ""
        Dim strUnits As String = ""
        Dim dpl As New List(Of DatasetPair)
        Try
            dpl = DatasetPairDB.GetExportDatasetGroupDetail(intDatasetGroupId)
            Dim objgraph As New GraphReport
            For Each dp As DatasetPair In dpl

                objgraph.DataVersionIdOne = dp.DataVersionIdOne.ToString
                objgraph.DataVersionIdTwo = dp.DataVersionIdTwo.ToString
                objgraph.MetricName = dp.MetricName.ToString
                objgraph.GraphTitle = "TEST"
                graphs.Add(objgraph)
            Next

            For Each g As GraphReport In graphs

                If MatchingMetricUnits(g) = Nothing Then
                    MessageBox.Show(g.DataVersionIdOne.ToString & " and " & g.DataVersionIdTwo.ToString & " do not have corresponding units!", "Erro")
                    Return Nothing
                    Exit Function
                Else
                    strUnits = MatchingMetricUnits(g)
                    Units = strUnits
                End If

                Dim ds As New DataTable
                ds = ReportDB.GetDeltaSeriesData(g.DataVersionIdOne, g.DataVersionIdTwo, g.MetricName)

                Dim dtgv As New DataTable
                dtgv = ReportDB.GetDeltaReportData(g.DataVersionIdOne, g.DataVersionIdTwo, g.MetricName)

                If dtgv.Rows.Count < 1 Then
                    MessageBox.Show("No Data")
                    Return Nothing
                    Exit Function
                End If

                Dim newtable As New DataTable

                dset.Tables.Add(dtgv)
                For Each table As DataTable In dset.Tables
                    newtable.Merge(table)
                Next
                dgvGraphResults.DataSource = newtable
                Me.DgvTable = newtable

                Dim strSeriesName As String = g.DataVersionIdOne.ToString & " - " & g.DataVersionIdTwo.ToString
                MySeriesName = strSeriesName

                strTitleName = g.GraphTitle.ToString
                MyMetricName = g.GraphTitle.ToString

            Next
            Return DgvTable

        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString & Err.Number.ToString)
            Return Nothing
        End Try

    End Function

Open in new window

0
Comment
Question by:chtullu135
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 

Author Comment

by:chtullu135
ID: 33568560
Further troubleshooting revealed that the following loop is not populating objgraph properly
 dpl = DatasetPairDB.GetExportDatasetGroupDetail(intDatasetGroupId)
            Dim objgraph As New GraphReport
            For Each dp As DatasetPair In dpl

                objgraph.DataVersionIdOne = dp.DataVersionIdOne.ToString
                objgraph.DataVersionIdTwo = dp.DataVersionIdTwo.ToString
                objgraph.MetricName = dp.MetricName.ToString
                objgraph.GraphTitle = "TEST"
                graphs.Add(objgraph)
            Next
0
 

Accepted Solution

by:
chtullu135 earned 0 total points
ID: 33568658
I found the problem.  It was pretty basic.  I needed to instantiate objgraph in the first line of the for loop instead of before the start of the for loop, otherwise it would be overwritten with the latest data
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net creating Contact in Outlook 1 97
Filtering a datagrid view 8 45
Send SMS from vb.net desktop app 30 51
vb.net code 9 28
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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