DataView.RowFilter doesn't work

Discussion in 'MCSD' started by jacksu, Mar 1, 2004.

  1. jacksu

    jacksu Guest

    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
    jacksu, Mar 1, 2004
    #1
    1. Advertising

  2. jacksu

    EC Guest

    Try putting 3 between single quotes:
    dv.RowFilter = "type='3'";


    "jacksu" <> wrote in message
    news:4df601c3ffd3$29843b60$...
    > 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
    >
    EC, Mar 2, 2004
    #2
    1. Advertising

  3. jacksu

    jacksu Guest

    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" <> wrote in

    message
    >news:4df601c3ffd3$29843b60$...
    >> 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
    >>

    >
    >
    >.
    >
    jacksu, Mar 2, 2004
    #3
  4. jacksu

    Luis Lino Guest

    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" <> wrote in

    message
    >news:4df601c3ffd3$29843b60$...
    >> 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
    >>

    >
    >
    >.
    >
    Luis Lino, Mar 2, 2004
    #4
  5. 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" <> wrote in message
    news:4df601c3ffd3$29843b60$...
    > 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
    >
    Daniel Joskovski, Mar 2, 2004
    #5
  6. jacksu

    Rugen

    Joined:
    Apr 20, 2007
    Messages:
    1
    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'";



    Rugen, Apr 20, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?cnNwaWRlbg==?=

    wizard doesn't work

    =?Utf-8?B?cnNwaWRlbg==?=, Jul 31, 2004, in forum: Wireless Networking
    Replies:
    1
    Views:
    1,135
    =?Utf-8?B?cnNwaWRlbg==?=
    Jul 31, 2004
  2. jacksu
    Replies:
    2
    Views:
    1,218
    jacksu
    Feb 23, 2004
  3. pcbutts1
    Replies:
    2
    Views:
    883
    pcbutts1
    Jul 26, 2005
  4. webaccess

    Problem In datagrid/dataview

    webaccess, Jan 7, 2008, in forum: General Computer Support
    Replies:
    0
    Views:
    802
    webaccess
    Jan 7, 2008
  5. John Navas

    PSE6: Work-around when Help doesn't work under Windows

    John Navas, Jan 12, 2008, in forum: Digital Photography
    Replies:
    3
    Views:
    446
    John Navas
    Jan 14, 2008
Loading...

Share This Page