Results 1 to 7 of 7

Thread: [RESOLVED] Data Sets - Databases

  1. #1

    Thread Starter
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Resolved [RESOLVED] Data Sets - Databases

    Alright I have a project where I load a database table into a DataSet and DataAdapter using SQLClient.SqlConnection. I am using this to create reports and I am trying to add dynamic filters to the report ( Only view certain items, select by name, things like that ). Now, currently I have to use a whole new query and grab that from the database every time I change the output specifications. Is there a way I can skip going through the database and just Query the original DataSet that I have created ?

    Code:
       Dim oConn As SqlClient.SqlConnection = New SqlClient.SqlConnection(cString)
       Dim tAdap As SqlClient.SqlDataAdapter
       Dim sQuery As String = "SELECT * FROM ReportView"
       Dim dSet As DataSet
     
       ' Code in here that adds to the query when specific items are selected
       ' ex. WHERE fieldA = 1 AND name = 'Nick'
     
       tAdap = New SqlClient.SqlDataAdapter(sQuery, oConn)
       dSet = New DataSet()
       tAdap.Fill(dSet, table)
    
       ' Using the DevExpress Framework (.repx is a report file)
       rep = XtraReport.FromFile("reportView.repx", True)
       rep.DataSource = dSet
       rep.DataAdapter = tAdap
       rep.DataMember = table
    Thanks for your help..

  2. #2
    Lively Member
    Join Date
    Jun 2004
    Posts
    99

    Re: Data Sets - Databases

    Have you tried filtering the defaultview of the dataset? Not sure if reports look at this but I know most controls do.

    dSet.Tables(0).DefaultView.RowFilter = "(fieldA = 1) AND (name = 'Nick')"

  3. #3

    Thread Starter
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: Data Sets - Databases

    Thank you for that, that helps a lot with the views...
    Now is there any way to do that with the sort order ? asc ? desc ?

    thanks.

  4. #4
    New Member TirRaven's Avatar
    Join Date
    May 2007
    Posts
    14

    Re: Data Sets - Databases

    yes, in a similar fashion to filtering the data it can be sorted with the RowFilter property of the datatable.

    Code:
    'sort ascending
            dSet.Tables(0).DefaultView.RowFilter = "MyColumnName ASC"
    'sort descending
            dSet.Tables(0).DefaultView.RowFilter = "MyColumnName DESC"

  5. #5

    Thread Starter
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: Data Sets - Databases

    Thanks for all the help.

  6. #6

    Thread Starter
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: Data Sets - Databases

    Quote Originally Posted by TirRaven
    yes, in a similar fashion to filtering the data it can be sorted with the RowFilter property of the datatable.

    Code:
    'sort ascending
            dSet.Tables(0).DefaultView.RowFilter = "MyColumnName ASC"
    'sort descending
            dSet.Tables(0).DefaultView.RowFilter = "MyColumnName DESC"
    Just for Reference:
    Code:
    'sort Ascending
            dSet.Tables(0).DefaultView.Sort = "MyColumnName ASC"
    'sort Descending
            dSet.Tables(0).DefaultView.Sort = "MyColumnName DESC"
    Use the Sort function instead of the Row Filter for sorting by columns.

    -NP

  7. #7
    New Member TirRaven's Avatar
    Join Date
    May 2007
    Posts
    14

    Re: Data Sets - Databases

    Quote Originally Posted by NPassero

    Use the Sort function instead of the Row Filter for sorting by columns.

    -NP

    oops haha, yea thats what i ment to post...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width