数据表VS数据视图
Hy,我真的不明白datatable和dataview之间的区别,因为我们可以这样做:
Dim dtb As New DataTable() Dim dtv As DataView = dtb.DefaultView
提前致谢 。
Datatable
是根据您的数据库查询提取的无序且未经过滤的DataRows集合。
DataView(您可以拥有多个)是相同数据的过滤和/或有序视图。
例如:
using(SqlConnection cn = GetConnection()) { cn.Open(); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Customers", cn); DataTable dt = new DataTable(); da.Fill(dt); // At this point dt is filled with datarows extracted from the database in no particular order // And the DefaultView presents the same record organization (or lack of), but... // Order on the default view by CustomerName dt.DefaultView.Sort = "CustomerName"; foreach(DataRowView rv in dt.DefaultView) Console.WriteLine(rv["CustomerName"].ToString(); // A new dataview with only a certain kind of customers ordered by name DataView dvSelectedCust = new DataView(dt, "CreditLevel = 1", "CustomerName", DataViewRowState.Unchanged); foreach(DataRowView rv in dvSelectedCust) Console.WriteLine(rv["CustomerName"],ToString(); }
当然,创建和维护DataView会对性能产生影响,因此您可以选择仅在您真正需要时才使用它
有许多与此相关的互联网链接,但总结
DataView是DataTable的自定义视图,用于排序,过滤,搜索,编辑和导航。 DataView不存储数据,而是表示其相应DataTable的连接视图。
您可以在VB中查看简单的DataView 示例 。
DataView是用于过滤或应用表达式排序等的附加层。
DataView包含RowFilter
等运算符
链接: http : //msdn.microsoft.com/fr-fr/library/system.data.dataview.aspx
上述就是C#学习教程:数据表VS数据视图分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/954540.html