public DataView(); public DataView(DataTable); |
DataView dv; dv = new DataView(theDataSet.Tables["Employees"]); |
DataView dv = new DataView(); dv.Table = theDataSet.Tables["Employees"]; DataView构造函数使你由DataTable中得到一个DataView对象。如果需要,反之亦可。事实上,DataTable对象的DefaultView属性返回一个该表的DataView对象。 DataView dv = dt.DefaultView; |
public virtual string RowFilter {get; set;} |
dv.RowFilter = "Country = 'USA'"; dv.RowFilter = "EmployeeID >5 AND Birthdate < #1/31/82#" dv.RowFilter = "Description LIKE '*product*'" |
dv.RowFilter = "employeeID IN (2,4,5)" |
dv.RowFilter = "Description LIKE '[[]*[]]product[[]*[]]" |
dv.RowFilter = "Description LIKE 'prod*ct" |
IIF(expression, if_true, if_false) |
IIF(employeeID<6, Len(lastname) %2 =0, Len(lastname) %2 >0) |
Dim dv As New DataView() dv = ds.Tables("Employees").DefaultView dv.RowFilter = "employeeid >5" ListBox1.Items.Clear() Dim buf As String Dim dr As DataRowView For Each dr In dv buf = "" buf &= dr("lastname").ToString()& ", " & dr("firstName").ToString() ListBox1.Items.Add(buf) Next |
CurrentRows | 包括所有未更新的、新的和修改的数据行 |
Deleted | 所有自上次调用AcceptChanges后删除的数据行 |
ModifiedCurrent | 所有自上次调用AcceptChanges后修改过的数据行 |
ModifiedOriginal | 所有自上次调用AcceptChanges后original版本的数据行 |
New | 所有自上次调用AcceptChanges后新添加的行 |
OriginalRows | 返回初始数据行,包含unchanged和deleted 的 |
Unchanged | 所有未更新的数据行 |
theMasterGrid.DataSource = m_ds.Tables("Employees").DefaultView |
m_ds.Tables("Employees").DefaultView.Sort = "lastname" theMasterGrid.DataSource = m_ds.Tables("Employees").DefaultView |
Dim dvm As DataViewManager dvm = New DataViewManager(m_ds) |
Dim dvm As DataViewManager = m_ds.DefaultViewManager |
Dim dvm As New DataViewManager() dvm.DataSet = m_ds |
Dim dvs As DataViewSetting dvs = dvm.DataViewSettings("Employees") dvs.Sort = "lastname" |
theMasterGrid.DataSource = dvm theMasterGrid.DataMember = "Employees" |
//默认显示
void ViewData(DataTable dt)
{
DataView dv = new DataView(dt);
//或者DataView dv=dt.DataView();
this.DataList1.DataSource = dv;
this.DataList1.DataBind();
}
//倒序显示
void ViewData_Sort(DataTable dt)
{
DataView dv = new DataView();
dv.Table = dt;
dv.Sort = "UserID DESC";
this.DataList1.DataSource = dv;
this.DataList1.DataBind();
}
//字符长度筛选控制显示
void ViewData_Len(DataTable dt)
{
DataView dv = new DataView();
dv.Table = dt;
dv.RowFilter = "Len(title)>4";
this.DataList1.DataSource = dv;
this.DataList1.DataBind();
}
//字符类似筛选控制显示
void ViewData_Like(DataTable dt)
{
DataView dv = new DataView();
dv.Table = dt;
dv.RowFilter = "Address like '%北京%'";
this.DataList1.DataSource = dv;
this.DataList1.DataBind();
}
//多个筛选控制显示
void ViewData_More_Like(DataTable dt)
{
DataView dv = new DataView();
dv.Table = dt;
dv.RowFilter = "Address like '%北京%'";
this.DataList1.DataSource = dv;
this.DataList1.DataBind();
}