Solved

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

Posted on 2007-04-04
2
557 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 500 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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