Solved

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Single Form 8 42
Help with C#, MVC, razor. 6 34
Reading the Web.Config using IIS 7.5? 4 35
How to parse the string and split the sub directory names in asp.net 7 38
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 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