Solved

There is no row at position 1

Posted on 2007-04-03
5
1,051 Views
Last Modified: 2009-12-16
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)

DateIndex = Index + 1

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

Dim myDs As DataSet = dbManager.ExecuteDataSet(cmd)

Dim myTable As DataTable = myDs.Tables(0)

===== > Dim myRow As DataRow = myTable.Rows(Index)

Dim row As DataRow = myTable.NewRow()

row.ItemArray = myRow.ItemArray

Next

Return retVal

End Function
0
Comment
Question by:mathieu_cupryk
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:dungla
ID: 18848046
Dim myTable As DataTable = myDs.Tables(0)
Dim myRow As DataRow
' check myTable first
If myTable.Rows.Count >= Index Then
 myRow = myTable.Rows(Index)
End If
Dim row As DataRow = myTable.NewRow()
0
 

Author Comment

by:mathieu_cupryk
ID: 18848327
If myTable.Rows.Count >= Index Then
 myRow = myTable.Rows(Index)
End If
Why does this happen?

with with the rows, because there is information to be added.
0
 
LVL 13

Accepted Solution

by:
dungla earned 500 total points
ID: 18848459
I don't know what is Index variable values. Can you show me entire your code (declare Index and assign it value).

I need to check the index of row because maybe your table have number of row less than the value of Index
0
 

Author Comment

by:mathieu_cupryk
ID: 18848538
Here it is.
Private dbManager As Database = DatabaseFactory.CreateDatabase("DevConfigServer")

        Public Function IncrementDate(ByVal DtPeriod As String, ByVal IncrementAmount As Integer) As String
            Dim strResults As String
            Dim intYear As Integer
            Dim intMonth As Integer
            intYear = Int32.Parse(DtPeriod.Substring(0, 4))
            intMonth = Int32.Parse(DtPeriod.Substring(4, 2))
            intMonth += IncrementAmount
            If intMonth > 12 Then
                intYear += 1
                intMonth -= 12
            End If
            strResults = intYear.ToString & intMonth.ToString().PadLeft(2, "0")
            'strResults = intYear.ToString & intMonth.ToString
            Return strResults
        End Function




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

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

DateIndex = Index + 1

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

Dim myDs As DataSet = dbManager.ExecuteDataSet(cmd)

Dim myTable As DataTable = myDs.Tables(0)

Dim myRow As DataRow = myTable.Rows(Index)  <===========

Dim row As DataRow = myTable.NewRow()

row.ItemArray = myRow.ItemArray

Next

Return retVal

End Function

0
 

Author Comment

by:mathieu_cupryk
ID: 18851033
Good job.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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