Solved

There is no row at position 1

Posted on 2007-04-03
5
1,032 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 160
detecting  the added row index in a datagridview 3 60
Not showing JavaScript in the list 5 38
C# Single Form 8 28
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

15 Experts available now in Live!

Get 1:1 Help Now