熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#高級編程:選擇數據[2]

2022-06-13   來源: .NET編程 
    ——此文章摘自《C#高級編程(第版)》定價元 特價元 購買

                      Phone = @Phone Fax = @Fax
                  WHERE (CustomerID = @Original_CustomerID)
                  AND (Address = @Original_Address OR @Original_Address IS NULL
    AND Address IS NULL )
    AND (City = @Original_City OR @Original_City IS NULL AND City IS NULL)
                  AND (CompanyName = @Original_CompanyName)
                  AND (ContactName = @Original_ContactName OR @Original_ContactName IS NULL
     AND ContactName IS NULL ) 
                  AND (ContactTitle = @Original_ContactTitle OR @Original_ContactTitle IS NULL
     AND ContactTitle IS NULL )
                  AND (Country = @Original_Country OR @Original_Country IS NULL
    AND Country IS NULL )
                  AND (Fax = @Original_Fax OR @Original_Fax IS NULL AND Fax IS NULL)
                  AND (Phone = @Original_Phone OR @Original_Phone IS NULL AND Phone IS NULL)
                  AND (PostalCode = @Original_PostalCode OR @Original_PostalCode IS NULL
    AND PostalCode IS NULL )
                  AND (Region = @Original_Region OR @Original_Region IS NULL
    AND Region IS NULL );
                  SELECT CustomerID CompanyName ContactName ContactTitle
                       Address City Region PostalCode Country Phone Fax
                  FROM Customers
                  WHERE (CustomerID = @ CustomerID);       
    thissqlUpdateCommandConnection = thissqlConnection;
    thissqlUpdateCommandParamatersAdd(
          new SystemDataSqlClientSqlParamater(@CustomerID
              SystemDataSqlDbTypeNVarChar CustomerID));
    // Other Paramaters omitted for clarity

    這些命令中的主要部分是已經生成的SQL對於INSERT和UPDATE命令有兩條SQL語句—— 一條語句用於插入或更新數據另一條語句用於重新從數據庫中選擇數據行

    這些看起來多余的子句是使客戶機上的數據與服務器上數據重新保持同步的一種方式默認情況下在插入時這些語句會應用到列上否則數據庫的觸發器就會更新已插入/更新記錄中的列數據的重新同步有一些優點用於重新選擇數據的@CustomerID參數與主鍵碼的INSERT/UPDATE語句中的值相等——  名稱是由向導自動生成的

    對於包含IDENTITY列的表生成的SQL會在插入語句後使用@@IDENTITY值如第章所述利用@@IDENTITY生成主鍵碼會產生一些惱人的錯誤因此要手工修改SQL的這個地方同樣如果沒有計算好列在更新了一些數據後重新選擇源表中的所有列就會浪費時間

    向導生成的代碼可以工作但有時它並不是最佳的對於產品系統所有生成的SQL語句都應用存儲過程的調用來替換如果INSERT或UPDATE子句不需要重新同步數據刪除多余的SQL子句可以加速應用程序的運行

[]  []  


From:http://tw.wingwit.com/Article/program/net/201311/15421.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.