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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Jan 9, 2013, 5:14 PM EST
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;
}
}
}
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 9, 2013, 5:51 PM EST
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.