你可以看下msdn,上面解释的很清楚啦 [Visual Basic] Private Sub MakeDataView() Dim dv As DataView dv = New DataView With dv .Table = DataSet1.Tables("Suppliers") .AllowDelete = True .AllowEdit = True .AllowNew = True .RowFilter = "City = 'Berlin'" .RowStateFilter = DataViewRowState.ModifiedCurrent .Sort = "CompanyName DESC" End With
' Simple bind to a TextBox control Text1.DataBindings.Add("Text", dv, "CompanyName") End Sub[C#] private void MakeDataView() { DataView dv = new DataView(); dv.Table = DataSet1.Tables["Suppliers"]; dv.AllowDelete = true; dv.AllowEdit = true; dv.AllowNew = true; dv.RowFilter = "City = 'Berlin'"; dv.RowStateFilter = DataViewRowState.ModifiedCurrent; dv.Sort = "CompanyName DESC";
// Simple bind to a TextBox control Text1.DataBindings.Add("Text", dv, "CompanyName"); }
如:MyTable.DefaultView.RowFilter = "city = 上海" ,如果绑定到表格,你就会看到只显示城市为上海的记录
就像sql语句的where 子句,这样比喻不知恰当否?
[Visual Basic]
Private Sub MakeDataView()
Dim dv As DataView
dv = New DataView
With dv
.Table = DataSet1.Tables("Suppliers")
.AllowDelete = True
.AllowEdit = True
.AllowNew = True
.RowFilter = "City = 'Berlin'"
.RowStateFilter = DataViewRowState.ModifiedCurrent
.Sort = "CompanyName DESC"
End With
' Simple bind to a TextBox control
Text1.DataBindings.Add("Text", dv, "CompanyName")
End Sub[C#]
private void MakeDataView()
{
DataView dv = new DataView(); dv.Table = DataSet1.Tables["Suppliers"];
dv.AllowDelete = true;
dv.AllowEdit = true;
dv.AllowNew = true;
dv.RowFilter = "City = 'Berlin'";
dv.RowStateFilter = DataViewRowState.ModifiedCurrent;
dv.Sort = "CompanyName DESC";
// Simple bind to a TextBox control
Text1.DataBindings.Add("Text", dv, "CompanyName");
}