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


Help Sorting Dataset

Posted on 2006-04-21
Medium Priority
Last Modified: 2008-02-07
I need some help with this....I am trying to write a function that takes my dataset, and returns a dataset sorted by Name.

Here is What I have so far...

 Public Function SortData(ByRef ds As DataSet) As DataSet
  Dim dv As New DataView
        dv.DataViewManager.DataSet = ds
        dv.Table = ds.Tables(0)
        dv.Sort = "NAME"
        Dim NewDs As DataSet
        NewDs.Tables(0).DefaultView.DataViewManager.DataSet = dv.DataViewManager.DataSet

        Return NewDs
end function

but I get the following error:
Server Error in '/bookstore' Application.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 349:    Public Function SortData(ByRef ds As DataSet) As DataSet
Line 350:        Dim dv As New DataView
Line 351:        dv.DataViewManager.DataSet = ds
Line 352:        dv.Table = ds.Tables(0)
Line 353:        dv.Sort = "NAME"

Source File: c:\inetpub\wwwroot\bookstore\ssl\Management\Controls\n_FeaturedProductAdmin.ascx.vb    Line: 351

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   StoreFront.StoreFront.n_FeaturedProductAdmin.SortData(DataSet& ds) in c:\inetpub\wwwroot\bookstore\ssl\Management\Controls\n_FeaturedProductAdmin.ascx.vb:351
   StoreFront.StoreFront.n_FeaturedProductAdmin.BindData(Int32 val) in c:\inetpub\wwwroot\bookstore\ssl\Management\Controls\n_FeaturedProductAdmin.ascx.vb:318
   StoreFront.StoreFront.n_FeaturedProductAdmin.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\bookstore\ssl\Management\Controls\n_FeaturedProductAdmin.ascx.vb:64
   System.Web.UI.Control.OnLoad(EventArgs e)

Question by:peterdidow
1 Comment
LVL 35

Accepted Solution

YZlat earned 2000 total points
ID: 16511428
Public Function SortData(ByRef ds As DataSet) As DataSet
  Dim dv As New DataView(ds.Tables(0))
        dv.Sort = "NAME"
        Dim NewDs As DataSet
      return NewDS
End Function

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

825 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