Help Sorting Dataset

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)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()

 
peterdidowAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

YZlatCommented:
Public Function SortData(ByRef ds As DataSet) As DataSet
  Dim dv As New DataView(ds.Tables(0))
        dv.Sort = "NAME"
        Dim NewDs As DataSet
        NewDs=dv.DataViewManager.DataSet.Copy
      return NewDS
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.