Help Sorting Dataset

Posted on 2006-04-21
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

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    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…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    794 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

    16 Experts available now in Live!

    Get 1:1 Help Now