利用DataRelation的验证和导航功能来提高应用程序的开发效率。
by Paul Delcogliano
技术工具箱:VB.NET, SQL Server 2000
在ADO.NET中包含许多能够提高开发性能及节省开发时间的类,DataRelation类就是其中的一个。它能通过在客户端执行数据完整性(data-integrity)验证来提高应用程序的运行速度。你可以通过运用DataRelation 的导航功能来缩短开发时间,它使你无需在相关的DataTable之间编写自定义代码来操纵数据。我会通过对DataRelation类的详细讲解来说明如何利用这个类来提高应用程序的开发。
private void CreateRelation() { // Get the DataColumn objects from two DataTable objects in a DataSet. DataColumn parentCol; DataColumn childCol; // Code to get the DataSet not shown here. parentCol = DataSet1.Tables["table1"].Columns["CustID"]; childCol = DataSet1.Tables["table12"].Columns["CustID"]; // Create DataRelation. DataRelation relCustOrder; relCustOrder = new DataRelation("table3", parentCol, childCol); // Add the relation to the DataSet. DataSet1.Relations.Add(relCustOrder); }