| Application.Run(new DisconnectedDataForm());
}
}
The InitData method in Listing 1 contains the methods necessary to set up the SqlDataAdapter and DataSet. Notice that various data objects are defined at class level so they can be used in multiple methods. The DataGrid''''s DataSource property is set in the constructor. Whenever a user clicks the Update button, the Update method in the btnUpdateClicked event handler is called, pushing modifications back to the data base.
Listing1中的InitData方法包含需要建立SqlDataAdapter和DataSet的方法。注意不同数据对象是被定义在class级别的,这样它们能够在多个方法中使用,DataGrid的DataSource属性在构造函数中设置。无论用户在何时点击更新按钮,在btnupdateClicked事件中的Update方法都被调用,将修改后的数据返回给数据库。
Summary
总结
DataSets hold multiple tables and can be kept in memory and reused. The SqlDataAdapter enables you to fill a DataSet and Update changes back to the data base. You don''''t have to worry about opening and closing the SqlConnection because the SqlDataAdapter does it automatically. A SqlCommandBuilder populates insert, update, and delete commands based on the SqlDataAdapter''''s select statement. Use the Fill method of the SqlDataAdapter to fill a DataSet with data. Call the SqlDataAdapter''''s Update method to push changes back to a data base.
DataSet存有多张表,能够保存在内存中并能够重用。SqlDataAdapter使你能够填充DataSet << 上一页 [11] [12] [13] [14] [15] [16] [17] [18] 下一页 |