473,831 Members | 2,341 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting dataset to dataview and sorting?

I have a dataset with one table, which has four columns. All are of
type INT. I need to convert this dataset into a dataview so I can sort
on the last three columns. I may sort one of the three or all three at
once. This dataview will display its results in a winform datagrid.

Right now, I create the dataset from a datareader:

while(dr.Read() )
{
drow = _filteredCriter iaDataSet.Table s[0].NewRow();
drow[0] = dr.GetValue(0);
drow[1] = dr.GetValue(1);
drow[2] = dr.GetValue(2);
drow[3] = dr.GetValue(3);
_filteredCriter iaDataSet.Table s[0].Rows.Add(drow) ;
}

How do I convert the dataset to a dataview then take the three criteria
and apply them to the new created dataview?

Thanks,
Brett

Dec 31 '05 #1
7 8730
KJ
Where "dt" represents your table and "foo" the column name to sort on:

DataView dv = new DataView(dt);
dv.Sort = "foo";

Dec 31 '05 #2
I did that but need to sort this way:

"col1 = " + col1criteria + " and col2 = " + col2criteria + " and col3 =
" + col3criteria

I apply that to the sortfilter but always get the same results in the
grid, which don't match the above sorting. I can look at "dv" in the
debugger and see its "Items". The row values are matching the criteria
I'm sending in. What could be causing it not to match the query?

Thanks,
Brett

Dec 31 '05 #3
KJ
OK, maybe you are thinking of the .Select method of DataTable?:

(from MSDN)

public DataRow[] Select(
string filterExpressio n,
string sort,
DataViewRowStat e recordStates
);

Dec 31 '05 #4
I did try .Select but get the same thing - nothing. For some reason,
none of the sorting or querying has any affect.

Brett

Dec 31 '05 #5
Brett,

Sorting is a way of ordering results.

What you are doing is trying to filter the results. You want to set the
RowFilter property to this string, and then it should filter your results
out appropriately.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Brett Romero" <ac*****@cygen. com> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com...
I did that but need to sort this way:

"col1 = " + col1criteria + " and col2 = " + col2criteria + " and col3 =
" + col3criteria

I apply that to the sortfilter but always get the same results in the
grid, which don't match the above sorting. I can look at "dv" in the
debugger and see its "Items". The row values are matching the criteria
I'm sending in. What could be causing it not to match the query?

Thanks,
Brett

Dec 31 '05 #6
RowFilter is what I'm setting.

Jan 3 '06 #7
I have what I believe to be a similar or the same problem.

I populate a DataSet with the results of an SQL query, and then apply a
DataView to this DataSet. I then iterate through the DataView Rows to create
an XML file.

My problem is, no matter what I do, the way the data is sorted is always the
same. so if I sort on "x, y, z" I have unsorted data in my XML file when it
is saved.

I don't think this has anything to do with RowFilter properties.

Thanks in advance

"Nicholas Paldino [.NET/C# MVP]" wrote:
Brett,

Sorting is a way of ordering results.

What you are doing is trying to filter the results. You want to set the
RowFilter property to this string, and then it should filter your results
out appropriately.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Brett Romero" <ac*****@cygen. com> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com...
I did that but need to sort this way:

"col1 = " + col1criteria + " and col2 = " + col2criteria + " and col3 =
" + col3criteria

I apply that to the sortfilter but always get the same results in the
grid, which don't match the above sorting. I can look at "dv" in the
debugger and see its "Items". The row values are matching the criteria
I'm sending in. What could be causing it not to match the query?

Thanks,
Brett


Jan 17 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
16386
by: Nikki | last post by:
Is it possible to sort a dataset rather than a dataview? I have a web service that returns a dataset which I would like to sort before returning it (this is so the sorting is standardised and so applications that see the results as xml don't have to fiddle around and sort it themselves later). I have tried sorting a dataview and adding that dataview's table to the dataset but the results don't remain sorted. The only way I can see to do...
2
1611
by: DraguVaso | last post by:
Hi, I have 2 comboboxes, both bound to a different DataView, but thoe DataViews are bound to 1 DataTable in 1 DataSet. Like this: Dim dvwList2 As New DataView dvwList2 = MyDataSet.Tables("tblAccounts").DefaultView dvwList2.Sort = "Account ASC" cmbAccount.DataSource = dvwList2
4
441
by: Deepa | last post by:
I have a dataset which am trying to sort by 3 specific columns. I am not making any connection to the database to get the dataset. I have the raw dataset already. What i tried doing was to create a DataView and sort it by a column name. mydataset.ReadXml(@sResponseXML); DataView mydataview = new DataView(); mydataview = ds.Tables.DefaultView; mydataview.Sort = "ColumnName";
4
10041
by: suzy | last post by:
hello. how can i sort data in a dataset? all the examples i have seen on msdn, etc are sorting a dataview. this works fine, but i want to return the results in xml and the dataview doesn't have a .getxml method (unlike the dataset). any ideas? thanks.
3
5350
by: Björn | last post by:
Hi List I´m generating a DataSet using a simple sql select statement. Now my DataSet has several rows with columns(ID,NAME,CAPTION) Now I want to sort the DataSet for column Caption. I can´t use sql "order by" because the caption field is of Sqltype text. So I wanted to use the DataView object sort order. ----sample code-------------------------- DataView sortView = this.sqlResultDS.Tables.DefaultView;//new
2
3703
by: Carl Summers | last post by:
I have a table in an Access database that has no sort applied in Access. When I fill a dataset with data from that table (the entire one dimensional table) my dataset is sorted differently than the database. This would not be a problem, and really isn't a problem except that it means I have to search the dataset each time I want to find a particular record instead of just storing a variable. Which brings me to a different question....
6
23343
by: Ramakrishnan Nagarajan | last post by:
Hi can any one help me in converting a DataView into a DataSet or a DataTable into a DataSet, I tried the following ways dSet= ((DataSet)_gridRegStudDetails.DataSource); dSet = ((DataSet)_gridRegStudDetails.DataSource).Tables.DataSet; studData = ((DataSet)dView).Tables.DataSet; But not working can you pls help me out
3
2768
by: Freeon | last post by:
Hi, I am looking for a way to sort a strong typed dataset. It would seem the most straightforward way is to use a dataview. The only problem is when I use the dataview I seem to loose the strong typed properties from my original dataset Anyone that can point me to an example of how to sort my dataset and maintain the use of my typed properties would be greatly appreciated Thank, Freeon
6
16745
by: Nick | last post by:
I have a code that returns data in IList. My webGrid doesn't allow me to sort with IList returned, it say it only suports DataView, DataTable and DataSet, not IEnumerable. I don't know how to return the DataSet type when using the following code: ======== this is my interface ====================== namespace WareHouse.DataLayer.DataObjects { /// <summary> /// Defines methods to access categories and products.
0
9793
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10777
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10534
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10207
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9317
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7748
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3963
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.