DataView dview = this.dsLlantas.Tables[0].DefaultView;
dview.Sort = "Fecha desc";
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jan 9, 2013, 10:51 PM
you have two way to filter dataset or datatable
1) use datatable.DefaultView and Row filter which is describ above
2) use datatable.Select()
Try..
DataTable dTable = new DataTable();
dTable.Columns.Add("Test1");
dTable.Columns.Add("Test2");
dTable.Columns.Add("Test3");
DataRow drow1 = dTable.NewRow();
drow1["Test1"] = "a";
drow1["Test2"] = "b";
drow1["Test3"] = "c";
DataRow drow2 = dTable.NewRow();
drow2["Test1"] = "aa";
drow2["Test2"] = "bb";
drow2["Test3"] = "cc";
DataRow drow3 = dTable.NewRow();
drow3["Test1"] = "ab";
drow3["Test2"] = "bb";
drow3["Test3"] = "ca";
dTable.Rows.Add(drow1);
dTable.Rows.Add(drow2);
dTable.Rows.Add(drow3);
dTable.DefaultView.RowFilter = "Test1='a'";
DataView dView = dTable.DefaultView;
var dataRowCollection = dTable.Select("Test1='a'");
hope this will help you.
Satyapriya NayakPosted Jan 9, 2013, 10:14 PM
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace DataTable_DefaultView_RowFilter
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
DataSet ds;
DataTable dt;
string str;
public Form1()
{
InitializeComponent();
}
private void btndisplayall_Click(object sender, EventArgs e)
{
bind();
}
void bind()
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from student";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
dt = ds.Tables["student"];
oledbda.Fill(ds, "student");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "student";
con.Close();
}
private void btndisplay_Click(object sender, EventArgs e)
{
bind();
dt = ds.Tables["student"];
dt.DefaultView.RowFilter="saddress='" + textBox1.Text.Trim()+"'";
dataGridView1.DataSource = dt.DefaultView;
}
}
}
------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace DataView_RowFilter
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void btndisplayall_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from student";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
oledbda.Fill(ds, "student");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "student";
con.Close();
}
private void btndisplay_Click(object sender, EventArgs e)
{
DataTable dt;
dt = ds.Tables["student"];
DataView dv = new DataView(dt);
dv.RowFilter = "sname='" + textBox1.Text + "'";
dataGridView1.DataSource = dv;
}
}
}