?
Solved

Urgent!!! Urgent! Only one row is being added to table.

Posted on 2007-04-04
8
Medium Priority
?
242 Views
Last Modified: 2010-04-16
When I trace the below code. I see that there are at least there rows for a MaxPeriod of

3. But the table just keeps adding the a new row to the same place.

For Index As Integer = 0 To MaxPeriod - 1

' Get date period

StoredProcName = dbName & ".dbo.usp_GetDatePeriodFromTo"

cmd = dbManager.GetStoredProcCommand(StoredProcName)

dbManager.AddInParameter(cmd, "@YEARMONTH", DbType.String, DtPeriod)



DtPeriod = IncrementDate(DtPeriod, DateIndex)

' Put the yearmonth, start date ,and end date in a dataset

Dim myDs As DataSet = dbManager.ExecuteDataSet(cmd)

' check myTable first

Dim myRow As DataRow


Dim myTable As DataTable = myDs.Tables(0)

If myTable.Rows.Count >= Index Then

myRow = myTable.Rows(Index)

End If

Dim row As DataRow = myTable.NewRow()

row.ItemArray = myRow.ItemArray



Next

Return retVal



0
Comment
Question by:mathieu_cupryk
[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
  • 5
  • 3
8 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 18849906
Like I said in our other thread,

You keep recreating the table every time through the loop.

If you want to ADD to the table, create a table OUTSIDE the loop and add rows INSIDE.
0
 

Author Comment

by:mathieu_cupryk
ID: 18850001
Dim myTable As DataTable = myDs.Tables(0)
?
0
 

Author Comment

by:mathieu_cupryk
ID: 18850012
Dim myDs As DataSet = New DataSet()
           
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mathieu_cupryk
ID: 18850018
How about this?

 Public Function GetBusinessCalendarPeriod(ByVal dbName As String, ByVal DatePeriod As String, ByVal txtMaxPeriod As String) As DataTable

            Dim retVal As New DataTable("BusinessCalendars")
            Dim DtPeriod As String = DatePeriod
            Dim MaxPeriod As Integer = Int32.Parse(txtMaxPeriod)
            Dim cmd As DbCommand
            Dim tmpds As DataSet = New DataSet()
            Dim StoredProcName As String = String.Empty
            Dim DateIndex As Integer = 1

            Dim myDs As DataSet = New DataSet()
           
            'We get the divisions
            For Index As Integer = 0 To MaxPeriod - 1
                ' Get date period

                StoredProcName = dbName & ".dbo.usp_GetDatePeriodFromTo"
                cmd = dbManager.GetStoredProcCommand(StoredProcName)
                dbManager.AddInParameter(cmd, "@YEARMONTH", DbType.String, DtPeriod)


                DtPeriod = IncrementDate(DtPeriod, DateIndex)
                ' Put the yearmonth, start date ,and end date in a dataset
                myDs = dbManager.ExecuteDataSet(cmd)

               ' check myTable first
                Dim myRow As DataRow
               
                Dim myTable As DataTable = myDs.Tables(0)

                If myTable.Rows.Count >= Index Then
                    myRow = myTable.Rows(Index)
                End If

                Dim row As DataRow = myTable.NewRow()

                row.ItemArray = myRow.ItemArray


            Next
            Return retVal

        End Function
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 18850408
I was expecting something more like:

    Public Function GetBusinessCalendarPeriod(ByVal dbName As String, ByVal DatePeriod As String, ByVal txtMaxPeriod As String) As DataTable
        Dim retVal As New DataTable("BusinessCalendars")
        retVal.Columns.Add("yearmonth")
        retVal.Columns.Add("startdate")
        retVal.Columns.Add("enddate")
        Dim DtPeriod As String = DatePeriod
        Dim MaxPeriod As Integer = Int32.Parse(txtMaxPeriod)
        Dim StoredProcName As String = dbName & ".dbo.usp_GetDatePeriodFromTo"

        'We get the divisions

        For Index As Integer = 0 To MaxPeriod - 1
            ' Get date period
            DtPeriod = IncrementDate(DtPeriod, Index + 1)
            'Dim cmd As DbCommand = dbManager.GetStoredProcCommand(StoredProcName)
             dbManager.AddInParameter(cmd, "@YEARMONTH", DbType.String, DtPeriod)

            Dim row As DataRow = retVal.NewRow()        ' Create new row as the index in the for increases

            'Put the yearmonth, start date ,and end date in a dataset
            Dim tmpds As Dataset = dbManager.ExecuteDataSet(cmd)        ' This will put it in a dataset
            row.ItemArray = tmpds.Tables(0).Rows(0).ItemArray
            retVal.Rows.Add(row)
        Next

        Return retVal
    End Function
0
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 2000 total points
ID: 18850430
This will be my last message to you.

A "C" is like a slap in the face.
0
 

Author Comment

by:mathieu_cupryk
ID: 18850447
why did u put    'Dim cmd As DbCommand = dbManager.GetStoredProcCommand(StoredProcName)
        in comments?
0
 

Author Comment

by:mathieu_cupryk
ID: 18851024
Excellent Excellent Job!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

762 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