打印本文 打印本文 关闭窗口 关闭窗口
第五课 使用断开数据--DataSet和SqlDataAdapter(翻译)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数15896  更新时间:2007/11/14 13:12:43  文章录入:mintao  责任编辑:mintao
DataSet赋值给Windows FormsDataGrid控件的一个示例:

dgCustomers.DataSource = dsCustomers;
dgCustomers.DataMember = "Customers";

The first thing we do, in the code above, is assign the DataSet to the DataSource property of the DataGrid.  This lets the DataGrid know that it has something to bind to, but you will get a ''''+'''' sign in the GUI because the DataSet can hold multiple tables and this would allow you to expand each available table.  To specify exactly which table to use, set the DataGrid''''s DataMember property to the name of the table.  In the example, we set the name to Customers, which is the same name used as the second parameter to the SqlDataAdapter Fill method.  This is why I like to give the table a name in the Fill method, as it makes subsequent code more readable.

上面代码中我们做的第一件事情就是将DataSet赋值给DataGrid控件的DataSource属性。这让DataGrid知道它要绑定到那里,但是你将在GUI中得到一个’+’符号,因为DataSet能够保存多个表并且它允许你展开每一个有效的表。为了指定真正要使用哪个表,应该将DataGrid控件的DataMember属性设置为表的名字。在这个例子当中,我们设置为Customers,它与SqlDataAdapterFill方法中使用的第二个参数具有相同名字。这就是为什么我喜欢在Fill方法中指定表名字的原因,这样在后面的代码中就更具有可读性。

 

Updating Changes

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ...  下一页 >> 

打印本文 打印本文 关闭窗口 关闭窗口