Solved

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

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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 article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

11 Experts available now in Live!

Get 1:1 Help Now