Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computer Certification > MCSD > DataView.RowFilter doesn't work

Reply
Thread Tools

DataView.RowFilter doesn't work

 
 
jacksu
Guest
Posts: n/a
 
      03-01-2004
Dear all,

I have a simple code to test the DataView. But it appears
the RowFilter doesn't work at all. Here is the code:

using System.Data;
using System;
using System.Data.SqlClient;

public class DBTest {
public static void Main() {
SqlConnection conn = new SqlConnection
("server=(local);uid=myid;pwd=mypwd;database=db1") ;

DataSet ds = new DataSet("tab1");
SqlDataAdapter da = new SqlDataAdapter
("select * from tab1", conn);
da.Fill(ds, "tab1");
DataView dv = new DataView(ds.Tables
["tab1"]);
dv.RowFilter = "type=3";

foreach (DataRow r in dv.Table.Rows) {
Console.WriteLine(">>" + r[0]
+ "\t" + r[1] + "\t" + r[2]);
}
conn.Close();
}
}

I got all the records back.

But if I change :
foreach (DataRow r in dv.Table.Rows) {

to
foreach (DataRow r in dv.Table.Select("type=3")) {

Then I got what I want.

Just wondering how to use DataView RowFilter properly.

Thanks in advance.

Jack

 
Reply With Quote
 
 
 
 
EC
Guest
Posts: n/a
 
      03-02-2004
Try putting 3 between single quotes:
dv.RowFilter = "type='3'";


"jacksu" <(E-Mail Removed)> wrote in message
news:4df601c3ffd3$29843b60$(E-Mail Removed)...
> Dear all,
>
> I have a simple code to test the DataView. But it appears
> the RowFilter doesn't work at all. Here is the code:
>
> using System.Data;
> using System;
> using System.Data.SqlClient;
>
> public class DBTest {
> public static void Main() {
> SqlConnection conn = new SqlConnection
> ("server=(local);uid=myid;pwd=mypwd;database=db1") ;
>
> DataSet ds = new DataSet("tab1");
> SqlDataAdapter da = new SqlDataAdapter
> ("select * from tab1", conn);
> da.Fill(ds, "tab1");
> DataView dv = new DataView(ds.Tables
> ["tab1"]);
> dv.RowFilter = "type=3";
>
> foreach (DataRow r in dv.Table.Rows) {
> Console.WriteLine(">>" + r[0]
> + "\t" + r[1] + "\t" + r[2]);
> }
> conn.Close();
> }
> }
>
> I got all the records back.
>
> But if I change :
> foreach (DataRow r in dv.Table.Rows) {
>
> to
> foreach (DataRow r in dv.Table.Select("type=3")) {
>
> Then I got what I want.
>
> Just wondering how to use DataView RowFilter properly.
>
> Thanks in advance.
>
> Jack
>



 
Reply With Quote
 
 
 
 
jacksu
Guest
Posts: n/a
 
      03-02-2004
I have tried, the same doesn't work. Actually the same
criteria, in RowFilter, doesn't work, but in
Table.Select, works.

Any more suggestion? Thanks a lot
Jack

>-----Original Message-----
>Try putting 3 between single quotes:
>dv.RowFilter = "type='3'";
>
>
>"jacksu" <(E-Mail Removed)> wrote in

message
>news:4df601c3ffd3$29843b60$(E-Mail Removed)...
>> Dear all,
>>
>> I have a simple code to test the DataView. But it

appears
>> the RowFilter doesn't work at all. Here is the code:
>>
>> using System.Data;
>> using System;
>> using System.Data.SqlClient;
>>
>> public class DBTest {
>> public static void Main() {
>> SqlConnection conn = new SqlConnection
>> ("server=(local);uid=myid;pwd=mypwd;database=db1") ;
>>
>> DataSet ds = new DataSet("tab1");
>> SqlDataAdapter da = new SqlDataAdapter
>> ("select * from tab1", conn);
>> da.Fill(ds, "tab1");
>> DataView dv = new DataView(ds.Tables
>> ["tab1"]);
>> dv.RowFilter = "type=3";
>>
>> foreach (DataRow r in dv.Table.Rows) {
>> Console.WriteLine(">>" + r[0]
>> + "\t" + r[1] + "\t" + r[2]);
>> }
>> conn.Close();
>> }
>> }
>>
>> I got all the records back.
>>
>> But if I change :
>> foreach (DataRow r in dv.Table.Rows) {
>>
>> to
>> foreach (DataRow r in dv.Table.Select("type=3")) {
>>
>> Then I got what I want.
>>
>> Just wondering how to use DataView RowFilter properly.
>>
>> Thanks in advance.
>>
>> Jack
>>

>
>
>.
>

 
Reply With Quote
 
Luis Lino
Guest
Posts: n/a
 
      03-02-2004
Hi

Try to use this sintax
instead of

foreach (DataRow r in dv.Table.Rows)

use

foreach (DataRowView r in dv)

Best regards
LL


>-----Original Message-----
>Try putting 3 between single quotes:
>dv.RowFilter = "type='3'";
>
>
>"jacksu" <(E-Mail Removed)> wrote in

message
>news:4df601c3ffd3$29843b60$(E-Mail Removed)...
>> Dear all,
>>
>> I have a simple code to test the DataView. But it

appears
>> the RowFilter doesn't work at all. Here is the code:
>>
>> using System.Data;
>> using System;
>> using System.Data.SqlClient;
>>
>> public class DBTest {
>> public static void Main() {
>> SqlConnection conn = new SqlConnection
>> ("server=(local);uid=myid;pwd=mypwd;database=db1") ;
>>
>> DataSet ds = new DataSet("tab1");
>> SqlDataAdapter da = new SqlDataAdapter
>> ("select * from tab1", conn);
>> da.Fill(ds, "tab1");
>> DataView dv = new DataView(ds.Tables
>> ["tab1"]);
>> dv.RowFilter = "type=3";
>>
>> foreach (DataRow r in dv.Table.Rows) {
>> Console.WriteLine(">>" + r[0]
>> + "\t" + r[1] + "\t" + r[2]);
>> }
>> conn.Close();
>> }
>> }
>>
>> I got all the records back.
>>
>> But if I change :
>> foreach (DataRow r in dv.Table.Rows) {
>>
>> to
>> foreach (DataRow r in dv.Table.Select("type=3")) {
>>
>> Then I got what I want.
>>
>> Just wondering how to use DataView RowFilter properly.
>>
>> Thanks in advance.
>>
>> Jack
>>

>
>
>.
>

 
Reply With Quote
 
Daniel Joskovski
Guest
Posts: n/a
 
      03-02-2004
In C# operator == (two equal signs) is operator for comparison, and =
(equal sign) is operator for assignment
next few lines are extract from code that works just that you wish.
Table is from famous Northwind

private void button1_Click(object sender, System.EventArgs e)

{

this.sqlDataAdapter1.Fill(dsCustomers1,"Customers" );

DataView dv=new DataView(dsCustomers1.Tables[0]);

dv.RowFilter="City='London'";

this.dataGrid1.DataSource=dv;

}

This is the right way of using the RowFilter property

Regards,

Daniel

"jacksu" <(E-Mail Removed)> wrote in message
news:4df601c3ffd3$29843b60$(E-Mail Removed)...
> Dear all,
>
> I have a simple code to test the DataView. But it appears
> the RowFilter doesn't work at all. Here is the code:
>
> using System.Data;
> using System;
> using System.Data.SqlClient;
>
> public class DBTest {
> public static void Main() {
> SqlConnection conn = new SqlConnection
> ("server=(local);uid=myid;pwd=mypwd;database=db1") ;
>
> DataSet ds = new DataSet("tab1");
> SqlDataAdapter da = new SqlDataAdapter
> ("select * from tab1", conn);
> da.Fill(ds, "tab1");
> DataView dv = new DataView(ds.Tables
> ["tab1"]);
> dv.RowFilter = "type=3";
>
> foreach (DataRow r in dv.Table.Rows) {
> Console.WriteLine(">>" + r[0]
> + "\t" + r[1] + "\t" + r[2]);
> }
> conn.Close();
> }
> }
>
> I got all the records back.
>
> But if I change :
> foreach (DataRow r in dv.Table.Rows) {
>
> to
> foreach (DataRow r in dv.Table.Select("type=3")) {
>
> Then I got what I want.
>
> Just wondering how to use DataView RowFilter properly.
>
> Thanks in advance.
>
> Jack
>



 
Reply With Quote
 
Rugen Rugen is offline
Junior Member
Join Date: Apr 2007
Posts: 1
 
      04-20-2007
I was in the same boat, and I didn't want to mess with a silly datagrid.

Pass the rowfilter when you setup your dataview object, instead of using the DataView.RowFilter method after; I think that only works at databinding. But then again, your .Select method would be just as much effective.

string rowfiltervariable = "Mumbo ='Jumbo'";
string sortvariable = "Mumba ASC";

DataView dv=new DataView(dsCustomers1.Tables[0], rowfiltervariable, sortvariable, DataViewRowState.CurrentRows);

//dv.RowFilter="City='London'";



[QUOTE=Daniel Joskovski]In C# operator == (two equal signs) is operator for comparison, and =
(equal sign) is operator for assignment
next few lines are extract from code that works just that you wish.
Table is from famous Northwind

private void button1_Click(object sender, System.EventArgs e)

{

this.sqlDataAdapter1.Fill(dsCustomers1,"Customers" );

DataView dv=new DataView(dsCustomers1.Tables[0]);

dv.RowFilter="City='London'";

this.dataGrid1.DataSource=dv;

}

This is the right way of using the RowFilter property

Regards,

Daniel
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE;Kontki if you delete kontiki any program you loaded with it in it 'will not work I have tried it with three programs and none work anymore (if you se it just stop download) 1-Twitch Computer Support 5 04-23-2009 02:45 PM
MS work around on text wrapping in a datagrid does not work TB ASP .Net 2 02-22-2006 10:34 PM
Hi I am new to asp i can not get it to work on xp pro sp2 even though the localhost work but asp pages dont so can some one help craig dicker ASP .Net 9 07-07-2005 11:52 AM
Re: Those cute little "WORK-SAFE" / "NOT WORK-SAFE" tags that people put in the Subject headers of their posts... Soapy Digital Photography 1 08-16-2004 12:07 PM
Re: Those cute little "WORK-SAFE" / "NOT WORK-SAFE" tags that people put in the Subject headers of their posts... Soapy Digital Photography 1 08-16-2004 06:24 AM



Advertisments