Program Logic to summaries Data

Posted on 2005-04-16
Last Modified: 2010-04-23
I have a stored Procedure which returns me route Information to build a route table. The return data looks like the sample below

I have a app which queries a MS Sql Table which returns me Phone nbr Prefixes,Start and End Nbrs
The field is called prefix ,start,end and has data like

Prefix                Trunk          
213232            Trunk 1
213235            Trunk 1                
213238            Trunk 1                
213239            Trunk 1              
213242            Trunk 2                
213243            Trunk 1          
213446            Trunk 1

to save space in my other apps i need to be able to get to be able to find all continues blocks and then summaries them like this

Start+ End       Start                        End           Trunk
213232_239     213232                    213239      Trunk 1
213242            213242                    213242      Trunk 2
213243_446     213446                    213446      Trunk 1

Question by:AlexPonnath
    LVL 14

    Accepted Solution

    Is the second table an existing table in SQL? If so, you can generate a datatable based on the table in SQL; if not, you'll write code to generate the table structure in both dataset and SQL.
    Suppose your stored procedure is used to generate a table named "tbl1", and your result table is called "tbl2". They are both in the same dataset "myDataSet".

    Dim StartNewRow As Boolean = True
    Dim Trunk As String
    Dim newRow As DataRow

    For Each dRow As DataRow In myDataSet.Tables("tbl1").Rows
        StartNewRow = Not (Trunk = dRow("Trunk"))
        If StartNewRow Then
            If Not newRow Is Nothing Then
            End If
            newRow = myDataSet.Tables("tbl2").NewRow
            Trunk = dRow("Trunk")
            newRow("StartEnd") = dRow("Prefix")
            newRow("Start") = dRow("Prefix")
            newRow("End") = dRow("Prefix")
            newRow("Trunk") = dRow("Trunk")
            newRow("StartEnd") = newRow("StartEnd").SubString(0, 6) & "_" & CStr(dRow("Prefix")).SubString(3, 3)
            newRow("End") = dRow("Prefix")
        End If

    ' Add last new row to tbl2
    If Not newRow Is Nothing Then
        newRow = Nothing
    End If


    Author Comment

    yje first one is a Table in SQl Server, the second one is the output i like to save to a Text file
    based on the Query and the logic..

    Author Comment

    Also i would like not to use a dataset if posible but rather use a data reader

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    733 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

    22 Experts available now in Live!

    Get 1:1 Help Now