[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..
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')"
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.
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"
Re: Data Sets - Databases
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
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...