Solved

There is no row at position 1

Posted on 2007-04-03
5
1,006 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Good job.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

7 Experts available now in Live!

Get 1:1 Help Now