[Last Call] Learn how to a build a cloud-first strategyRegister Now


Creating an In Memory Dataset

Posted on 2009-02-17
Medium Priority
Last Modified: 2012-05-06
I have two datasets:
ds2 ->Blank Dataset

I am looping through ds1 and want to place all the unchanged rows from ds1 into the new dataset ds2. ds2 resides only in memory and I am using it to validate data in a database table. Both datasets have the same columns. All i need is to get the rows from ds1 that are unchanged and put them in the new dataset. This seems like it would be easy but im pulling my hair out over here :-(

I am using the following code:

ds2.Tables("ORIGINAL").Columns.Add ("COL1")
ds2.Tables("ORIGINAL").Columns.Add ("COL2")
ds2.Tables("ORIGINAL").Columns.Add ("COL3")
ds2.Tables("ORIGINAL").Columns.Add ("COL4")

For intCount = 0 to ds1.Tables(0).Rows.Count - 1
     If ds1.Tables(0).Rows(intCount).RowState  = DataRowState.Unchanged Then
      End If

it seems simple enough but i am missing something here
Question by:imonfireDAMMIT
  • 2
  • 2

Expert Comment

ID: 23661981
What is the result of this code when you run it?

Author Comment

ID: 23662046
It returns blank rows without the data filled in
LVL 70

Expert Comment

by:Éric Moreau
ID: 23662068
You need to create a DataTable object first and then add it to your dataset. Here is an example I have:

    Private Sub CreateDataSet()
        'Creates a new dataset, 2 datatables and adds data to them
        mdsData = New DataSet("TestDataSet")
        Using dt As New DataTable("Countries")
            dt.Columns.Add("ID", GetType(Integer))
            dt.Columns.Add("Description", GetType(String))
            dt.LoadDataRow(New Object() {1, "Canada"}, True)
            dt.LoadDataRow(New Object() {2, "United States"}, True)
        End Using
        Using dt As New DataTable("States")
            dt.Columns.Add("ID", GetType(Integer))
            dt.Columns.Add("IDParent", GetType(Integer))
            dt.Columns.Add("Code", GetType(String))
            dt.Columns.Add("Description", GetType(String))
            dt.Columns.Add("Population", GetType(Integer))
            dt.LoadDataRow(New Object() {1, 1, "AB", "Alberta", 3153700}, True)
            dt.LoadDataRow(New Object() {2, 1, "BC", "British Columbia", 4146600}, True)
            dt.LoadDataRow(New Object() {3, 1, "MB", "Manitoba", 1162800}, True)
            dt.LoadDataRow(New Object() {4, 1, "NB", "New Brunswick", 750600}, True)
            dt.LoadDataRow(New Object() {5, 1, "NF", "Newfoundland", 519600}, True)
            dt.LoadDataRow(New Object() {6, 1, "NT", "Northwest Territories", 41900}, True)
            dt.LoadDataRow(New Object() {7, 1, "NS", "Nova Scotia", 936000}, True)
            dt.LoadDataRow(New Object() {8, 1, "NU", "Nunavut", 29400}, True)
            dt.LoadDataRow(New Object() {9, 1, "IPE", "Prince Edward Island", 137800}, True)
            dt.LoadDataRow(New Object() {10, 1, "ON", "Ontario", 12238300}, True)
            dt.LoadDataRow(New Object() {11, 1, "QC", "Québec", 7487200}, True)
            dt.LoadDataRow(New Object() {12, 1, "SK", "Saskatchewan", 994800}, True)
            dt.LoadDataRow(New Object() {13, 1, "YK", "Yukon", 31100}, True)
            dt.LoadDataRow(New Object() {14, 2, "CA", "California", 33872000}, True)
            dt.LoadDataRow(New Object() {15, 2, "TX", "Texas", 20852000}, True)
            dt.LoadDataRow(New Object() {16, 2, "NY", "New York", 18976000}, True)
            dt.LoadDataRow(New Object() {17, 2, "FL", "Florida", 15982000}, True)
            dt.LoadDataRow(New Object() {18, 2, "MA", "Maine", 1275000}, True)
            dt.LoadDataRow(New Object() {19, 2, "CO", "Colorado", 4301000}, True)
            dt.LoadDataRow(New Object() {20, 2, "NH", "New Hampshire", 1236000}, True)
        End Using
      End Sub

Open in new window

LVL 70

Accepted Solution

Éric Moreau earned 1500 total points
ID: 23662113
Your Add method is not adding any data!

You should try the LoadDataRow passing ds1.Tables(0).Rows(intCount) in parameters.

Author Closing Comment

ID: 31547988
I actually saw your comment about my add method not adding the data and it raised a flag. I realized my error and changed my code as follows:

For each dr1 in ds1.Tables(0).Rows
     If dr1.RowState = DataRowState.Unchanged Then
    End If

Thank you for your time

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month18 days, 13 hours left to enroll

834 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