?
Solved

row.ItemArray = myRow.ItemArray not set to an instance of an object.

Posted on 2007-04-04
2
Medium Priority
?
564 Views
Last Modified: 2012-05-05
Object reference not set to an instance of an object.

 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 >= 1 Then
                    myRow = myTable.Rows(Index)
                End If

                Dim row As DataRow = myTable.NewRow()

                row.ItemArray = myRow.ItemArray

                myTable.Rows.Add(row)  


            Next
           
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
2 Comments
 
LVL 10

Accepted Solution

by:
Si_Hibbard earned 2000 total points
ID: 18850568
This looks wrong to me - first why is the query in the loop, and then you are doing an assignment
row.ItemArray = myRow.ItemArray
even if you have never set myRow to anything

The error is telling you that you are trying to assign something to an object that has no value (has not been initialised) - eg -> "myRow.ItemArray" does not have a value

maybe you want something like the following - i cannot test it but it makes more sense from what i see:::

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

Dim myTable As DataTable = myDs.Tables(0)

'loop
For Index As Integer = 0 To MaxPeriod - 1
   
                ' check myTable first
                Dim myRow As DataRow

                If myTable.Rows.Count >= 1 Then
                    myRow = myTable.Rows(Index)          
                    Dim row As DataRow = myTable.NewRow()
                    row.ItemArray = myRow.ItemArray
                    myTable.Rows.Add(row)  
               End If

            Next
0
 

Author Comment

by:mathieu_cupryk
ID: 18851016
Good job!!!
0

Featured Post

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!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
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

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