Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8526533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:17:56+00:00 2026-06-11T08:17:56+00:00

I would like to ask for help regarding datasets and Crystal Reports. I have

  • 0

I would like to ask for help regarding datasets and Crystal Reports.

I have two DataTables in the DataSet, namely the DeliveredItems and DeliveryDetails. The problem that I have encountered is in the DeliveredItems part, wherein I’ve got an error in the line at:

dataSet.Tables("DeliveredItems").Rows.Add(row)

which gives me:

"The row already belongs to this table."

And upon tweaking the code, it returned an error:

"Object reference not set to an instance of an object."

My objective is to get all the items of the ListView along with their subitems inside the dataset to be displayed on a Crystal Report. Here’s my code:

Private Sub CreateReport()

    'Initialize the needed objects for report document.
    Dim myDeliveryReport As New rptDeliveryReceipt
    Dim row As DataRow = Nothing
    Dim row2 As DataRow = Nothing
    Dim dataSet As New DataSet
    Dim counter As Integer = lviDeliveryList.Items.Count
    Dim tempCount As Integer = 0
    Dim listViewItems As New ListViewItem()

    'Create a new DataTable named Delivery Details
    dataSet.Tables.Add("DeliveryDetails")

    'Create columns for the new DataTable named Delivery Details.
    With dataSet.Tables(0).Columns

        .Add("deliveryClientName", Type.GetType("System.String"))
        .Add("deliveryClientStreetAddress", Type.GetType("System.String"))
        .Add("deliveryClientCity", Type.GetType("System.String"))
        .Add("deliveryDRNumber", Type.GetType("System.String"))
        .Add("deliveryDate", Type.GetType("System.String"))
        .Add("deliveryPONumber", Type.GetType("System.String"))

    End With

    'Initialize and insert delivery heading to the DataTable.
    row = dataSet.Tables(0).NewRow
    row(0) = txtDeliveryTargetClient.Text
    row(1) = txtDeliveryClientAddress.Text
    row(2) = txtDeliveryClientCity.Text
    row(3) = txtDRNumber.Text
    row(4) = dtpDeliveryDate.Value.ToString
    row(5) = txtDRPO.Text
    dataSet.Tables(0).Rows.Add(row)

    'Create another DataTable called DeliveredItems
    dataSet.Tables.Add("DeliveredItems")

    'Create columns for the new DataTable named DeliveryItems.
    With dataSet.Tables(1).Columns

        .Add("deliveryCatNumber", Type.GetType("System.String"))
        .Add("deliveryItemDescription", Type.GetType("System.String"))
        .Add("deliveryItemQuantity", Type.GetType("System.String"))
        .Add("deliveryItemUnit", Type.GetType("System.String"))
        .Add("deliveryItemDetails", Type.GetType("System.String"))

    End With

    row = Nothing
    row = dataSet.Tables(1).NewRow

    'Store every data in an array for insertion.
    Dim deliveredItemsCount As Integer = lviDeliveryList.Items.Count
    Dim tempArray() As String
    ReDim tempArray(5)
    Dim deliveryListViewItem As New ListViewItem()

    For counter = 0 To deliveredItemsCount

        deliveryListViewItem = lviDeliveryList.Items.Item(counter)
        tempArray(0) = lviDeliveryList.Items.Item(counter).ToString
        tempArray(1) = deliveryListViewItem.SubItems(1).ToString
        tempArray(2) = deliveryListViewItem.SubItems(2).ToString
        tempArray(3) = deliveryListViewItem.SubItems(3).ToString
        tempArray(4) = deliveryListViewItem.SubItems(4).ToString

        'Insert new records to the DeliveredItems.
        row2(0) = tempArray(0)
        row2(1) = tempArray(1)
        row2(2) = tempArray(2)
        row2(3) = tempArray(3)
        row2(4) = tempArray(4)
        dataSet.Tables("DeliveredItems").Rows.Add(row)

        For counterClear = 0 To (deliveredItemsCount - 1)
            tempArray(counter) = Nothing
        Next counterClear

        row2 = Nothing

    Next counter

    'Set Data Sources for the Crystal Report.
    myDeliveryReport.SetDataSource(dataSet)
    frmDeliveryReceiptReport.crvDeliveryReceipt.ReportSource = myDeliveryReport

    'Dispose after using.
    dataSet.Dispose()
    dataSet = Nothing

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:17:58+00:00Added an answer on June 11, 2026 at 8:17 am

    In this line

     dataSet.Tables("DeliveredItems").Rows.Add(row) 
    

    you are adding row not row2 and row2 is never initialized
    I suppose you want to do:

    For counter = 0 To deliveredItemsCount   
    
        deliveryListViewItem = lviDeliveryList.Items.Item(counter)   
        tempArray(0) = lviDeliveryList.Items.Item(counter).ToString   
        .....
    
        row2 = dataSet.Tables("DeliveredItems").NewRow
        row2(0) = tempArray(0)   
        ......
        dataSet.Tables("DeliveredItems").Rows.Add(row2)   
    

    As a last note. I think you could avoid the tempArray… Set directly the values of row2 from the deliveryListViewItem. (remove also the array clearing at the end)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two list operations which I would like to ask for help. The
I have an encoding question and would like to ask for help. I notice
Good day everyone. I would like to ask for help regarding my code to
Hello I would like to ask your help regarding javascript code, how do I
Good morning! I would like to ask some help from you guys on how
I'm still fairly new to mysql and would like to ask for some help.
I would like to ask you: Imagine that you have a site and there
I would like to ask such question, I have XML xsd`s, which generate beans
I would like to ask you about regular expressions preg_match have outlined below. I
I would like to ask a help about Zensor which is a plugin that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.