SqlRowUpdatedEventArgs 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供活動資料 RowUpdated 。
public ref class SqlRowUpdatedEventArgs sealed : System::Data::Common::RowUpdatedEventArgs
public sealed class SqlRowUpdatedEventArgs : System.Data.Common.RowUpdatedEventArgs
type SqlRowUpdatedEventArgs = class
inherit RowUpdatedEventArgs
Public NotInheritable Class SqlRowUpdatedEventArgs
Inherits RowUpdatedEventArgs
- 繼承
範例
以下範例說明如何使用 和 RowUpdatingRowUpdated 事件。
該事件回 RowUpdating 傳以下輸出:
Event Arguments: (command=System.Data.SqlClient.SqlCommand commandType=2 status=0)
該事件回 RowUpdated 傳以下輸出:
事件參數:(command=System.Data.SqlClient.SqlCommand commandType=2 recordsAffected=1 row=System.Data.DataRow[37] status=0)
// handler for RowUpdating event
private static void OnRowUpdating(object sender, SqlRowUpdatingEventArgs e)
{
PrintEventArgs(e);
}
// handler for RowUpdated event
private static void OnRowUpdated(object sender, SqlRowUpdatedEventArgs e)
{
PrintEventArgs(e);
}
public static int Main()
{
const string connectionString = "...";
const string queryString = "SELECT * FROM Products";
// create DataAdapter
SqlDataAdapter adapter = new(queryString, connectionString);
SqlCommandBuilder builder = new(adapter);
// Create and fill DataSet (select only first 5 rows)
DataSet dataSet = new();
adapter.Fill(dataSet, 0, 5, "Table");
// Modify DataSet
DataTable table = dataSet.Tables["Table"];
table.Rows[0][1] = "new product";
// add handlers
adapter.RowUpdating += new SqlRowUpdatingEventHandler(OnRowUpdating);
adapter.RowUpdated += new SqlRowUpdatedEventHandler(OnRowUpdated);
// update, this operation fires two events
// (RowUpdating/RowUpdated) per changed row
adapter.Update(dataSet, "Table");
// remove handlers
adapter.RowUpdating -= new SqlRowUpdatingEventHandler(OnRowUpdating);
adapter.RowUpdated -= new SqlRowUpdatedEventHandler(OnRowUpdated);
return 0;
}
private static void PrintEventArgs(SqlRowUpdatingEventArgs args)
{
Console.WriteLine("OnRowUpdating");
Console.WriteLine(" event args: (" +
" command=" + args.Command +
" commandType=" + args.StatementType +
" status=" + args.Status + ")");
}
private static void PrintEventArgs(SqlRowUpdatedEventArgs args)
{
Console.WriteLine("OnRowUpdated");
Console.WriteLine(" event args: (" +
" command=" + args.Command +
" commandType=" + args.StatementType +
" recordsAffected=" + args.RecordsAffected +
" status=" + args.Status + ")");
}
' handler for RowUpdating event
Private Shared Sub OnRowUpdating(sender As Object, e As SqlRowUpdatingEventArgs)
PrintEventArgs(e)
End Sub
' handler for RowUpdated event
Private Shared Sub OnRowUpdated(sender As Object, e As SqlRowUpdatedEventArgs)
PrintEventArgs(e)
End Sub
Public Overloads Shared Function Main(args() As String) As Integer
Const connectionString As String = "..."
Const queryString As String = "SELECT * FROM Products"
' create DataAdapter
Dim adapter As New SqlDataAdapter(queryString, connectionString)
Dim builder As New SqlCommandBuilder(adapter)
' Create and fill DataSet (select only first 5 rows)
Dim dataSet As New DataSet()
adapter.Fill(dataSet, 0, 5, "Table")
' Modify DataSet
Dim table As DataTable = dataSet.Tables("Table")
table.Rows(0)(1) = "new product"
' add handlers
AddHandler adapter.RowUpdating, AddressOf OnRowUpdating
AddHandler adapter.RowUpdated, AddressOf OnRowUpdated
' update, this operation fires two events
'(RowUpdating/RowUpdated) per changed row
adapter.Update(dataSet, "Table")
' remove handlers
RemoveHandler adapter.RowUpdating, AddressOf OnRowUpdating
RemoveHandler adapter.RowUpdated, AddressOf OnRowUpdated
Return 0
End Function
Private Overloads Shared Sub PrintEventArgs(args As SqlRowUpdatingEventArgs)
Console.WriteLine("OnRowUpdating")
Console.WriteLine(" event args: (" & " command=" & args.Command.CommandText &
" commandType=" & args.StatementType & " status=" & args.Status & ")")
End Sub
Private Overloads Shared Sub PrintEventArgs(args As SqlRowUpdatedEventArgs)
Console.WriteLine("OnRowUpdated")
Console.WriteLine(" event args: (" & " command=" & args.Command.CommandText &
" commandType=" & args.StatementType & " recordsAffected=" &
args.RecordsAffected & " status=" & args.Status & ")")
End Sub
End Class
備註
RowUpdated當一Update行完成時,事件會被提升。
使用 Update時,每更新一列資料會發生兩個事件。 執行順序如下:
中的值 DataRow 會被移到參數值。
便會引發 OnRowUpdating 事件。
指令執行。
若指令設為
FirstReturnedRecord,且第一個回傳結果置於 DataRow。如果有輸出參數,它們會放在 DataRow中。
便會引發 OnRowUpdated 事件。
呼叫 AcceptChanges。
建構函式
| 名稱 | Description |
|---|---|
| SqlRowUpdatedEventArgs(DataRow, IDbCommand, StatementType, DataTableMapping) |
初始化 SqlRowUpdatedEventArgs 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| Command |
當被呼叫時Update(DataSet),取得或設定SqlCommand執行。 |
| Errors |
執行 Command 時,.NET 資料提供者產生的任何錯誤。 (繼承來源 RowUpdatedEventArgs) |
| RecordsAffected |
取得執行 SQL 陳述句時所變更、插入或刪除的列數。 (繼承來源 RowUpdatedEventArgs) |
| Row |
傳送 DataRow 是透過 Update(DataSet)。 (繼承來源 RowUpdatedEventArgs) |
| RowCount |
取得一批更新記錄中處理的列數。 (繼承來源 RowUpdatedEventArgs) |
| StatementType |
執行的 SQL 語句類型。 (繼承來源 RowUpdatedEventArgs) |
| Status |
取得 UpdateStatus 該 Command 財產。 (繼承來源 RowUpdatedEventArgs) |
| TableMapping |
傳送 DataTableMapping 是透過 Update(DataSet)。 (繼承來源 RowUpdatedEventArgs) |
方法
| 名稱 | Description |
|---|---|
| CopyToRows(DataRow[], Int32) |
將修改過的列的參考複製到所提供的陣列中。 (繼承來源 RowUpdatedEventArgs) |
| CopyToRows(DataRow[]) |
將修改過的列的參考複製到所提供的陣列中。 (繼承來源 RowUpdatedEventArgs) |
| Equals(Object) |
判斷指定的 物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |