程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> 關於微軟ADO.NET提供的組件庫裡的UpdateDataSet()的用法心得

關於微軟ADO.NET提供的組件庫裡的UpdateDataSet()的用法心得

編輯:.NET實例教程

這個是用了很早的SqlHelper.CS裡的函數做例子,但是實際上可以類推到現在微軟企業庫的Data組件部分。

函數是這樣寫的
/// <summary>
  /// Executes the respective command for each inserted, updated, or deleted row in the DataSet.
  /// </summary>
  /// <remarks>
  /// e.g.: 
  ///  UpdateDataset(conn, insertCommand, deleteCommand, updateCommand, dataSet, "Order");
  /// </remarks>
  /// <param name="insertCommand">A valid transact-SQL statement or stored procedure to insert new records into the data source</param>
  /// <param name="deleteCommand">A valid transact-SQL statement or stored procedure to delete records from the data source</param>
  /// <param name="updateCommand">A valid transact-SQL statement or stored procedure used to update records in the data source</param>
  /// <param name="dataSet">The DataSet used to update the data source</param>
  /// <param name="tableName">The DataTable used to update the data source.</param>
  public static void UpdateDataset(SqlCommand insertCommand, SqlCommand deleteCommand, SqlCommand updateCommand, DataSet dataSet, string tableName)
  {
   if( insertCommand == null ) throw new ArgumentNullException( "insertCommand" );
   if( deleteCommand == null ) throw new ArgumentNullException( "deleteCommand" );
   if( updateCommand == null ) throw new ArgumentNullException( "updateCommand" );
   if( tableName == null || tableName.Length == 0 ) throw new ArgumentNullException( "tableName" );

   // Create a SqlDataAdapter, and dispose of it after we are done
   using (SqlDataAdapter dataAdapter = new SqlDataAdapter())
   {
    // Set the data adapter commands
    dataAdapter.UpdateCommand = updateCommand;
    dataAdapter.InsertCommand = insertCommand;
  &nbs

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved