Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Performing a query on a dataset object

Performing a query on a dataset object

Scheduled Pinned Locked Moved ASP.NET
databasequestioncsharpasp-nethelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pankajdaga
    wrote on last edited by
    #1

    Hi everyone, I have an ASP.NET DataSet question. Is it possible to perform an SQL like query on a DataSet object? Basically, I want to filter a DataSet object. Of course, the query does not have to be a SQL like. Here is what I am trying to do. I have a report generation tool. So basically there would be one set of data and you can choose what kind of report you want to see. The filtering has to be done based on user choice. Any suggestions and help would be greatly appreciated. Sincerely, Pankaj Without struggle, there is no progress

    G R 2 Replies Last reply
    0
    • P pankajdaga

      Hi everyone, I have an ASP.NET DataSet question. Is it possible to perform an SQL like query on a DataSet object? Basically, I want to filter a DataSet object. Of course, the query does not have to be a SQL like. Here is what I am trying to do. I have a report generation tool. So basically there would be one set of data and you can choose what kind of report you want to see. The filtering has to be done based on user choice. Any suggestions and help would be greatly appreciated. Sincerely, Pankaj Without struggle, there is no progress

      G Offline
      G Offline
      gadgetfbi
      wrote on last edited by
      #2

      if you are binding to a control, pass the dataset to a dataview and you can filter by values in a colomn: c# DataView dv = new DataView; dv = MyDataSet.Tables[0].DefaultView; dv.Filter = "MyColomName = 'stringMatchExpresion'"; // Bind(); Hope this helps (hope i got the code close enough!!) www.fuxup.com[^]

      1 Reply Last reply
      0
      • P pankajdaga

        Hi everyone, I have an ASP.NET DataSet question. Is it possible to perform an SQL like query on a DataSet object? Basically, I want to filter a DataSet object. Of course, the query does not have to be a SQL like. Here is what I am trying to do. I have a report generation tool. So basically there would be one set of data and you can choose what kind of report you want to see. The filtering has to be done based on user choice. Any suggestions and help would be greatly appreciated. Sincerely, Pankaj Without struggle, there is no progress

        R Offline
        R Offline
        Ray Williams II
        wrote on last edited by
        #3

        The most simple way would be to use a DataView object to filter the records found within the DataSet. The DataView may be bound to most data bindable objects including DataGrids, DropDownLists, Reports, etc. The DataView also allows for sorting and filtering. Filtering is enabled using the RowFilter property of the DataView. The row filter acts much like the where clause in a Sql statement. Assuming your DataSet object is named myDataSet and it contains a single Table named "Contacts". C#:

        DataView myDataView = (DataView)myDataSet.Tables["Contacts"].DefaultView;
        // or DataView myDataView = (DataView)myDataSet.Tables[0].DefaultView;
        String myFilter = "City = 'Chicago'";
        myDataView.RowFilter = myFilter;
        myDataGrid.DataSource = myDataView;
        myDataGrid.DataBind();

        VB.NET

        Dim myDataView as DataView = CType(myDataSet.Tables("Contacts").DefaultView, DataView)
        ' or Dim myDataView as DataView = CType(myDataSet.Tables(0).DefaultView, DataView)
        Dim myFilter as String = "City = 'Chicago'"
        myDataView.RowFilter = myFilter
        myDataGrid.DataSource = myDataView
        myDataGrid.DataBind()

        Using the DataView object does not modify the source DataSet, so subsequent filtering of the DataSet can be performed. To insure that I can retrieve the filtered recordset across postbacks, I usually create a ViewState variable to hold the row filter value and use the DataView object as the standard binding object for data when filtering is needed. C#:

        In the Page.OnLoad event...
        If !(Page.IsPostBack)
        {
        ViewState["myFilter"] = "";
        }
        In the filtering event...
        ViewState["myFilter"] = myNewFilterString;
        In the data binding event...
        String myFilter = (String)ViewState["myFilter"];
        myDataView.RowFilter = myFilter;

        VB.NET

        In the Page.OnLoad event...
        If Not Page.IsPostBack Then
        ViewState("myFilter") = ""
        End If
        In the filtering event...
        ViewState("myFilter") = myNewFilterString;
        In the data binding event...
        Dim myFilter as String = CType(ViewState("myFilter"),String)
        myDataView.RowFilter = myFilter

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups