?
Solved

There is no row at position 1

Posted on 2007-04-03
5
Medium Priority
?
1,068 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
[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
  • 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 1000 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

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

743 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