SqlRowUpdatingEventArgs 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供活動資料 RowUpdating 。
public ref class SqlRowUpdatingEventArgs sealed : System::Data::Common::RowUpdatingEventArgs
public sealed class SqlRowUpdatingEventArgs : System.Data.Common.RowUpdatingEventArgs
type SqlRowUpdatingEventArgs = class
inherit RowUpdatingEventArgs
Public NotInheritable Class SqlRowUpdatingEventArgs
Inherits RowUpdatingEventArgs
- 繼承
範例
以下範例說明如何使用 和 RowUpdatingRowUpdated 事件。
該事件回 RowUpdating 傳以下輸出:
event args: (command=System.Data.SqlClient.SQLCommand commandType=2 status=0)
該事件回 RowUpdated 傳以下輸出:
event args: (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 CONNECTION_STRING = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer";
const string SELECT_ALL = "select * from Products";
//Create DataAdapter.
SqlDataAdapter rAdapter = new SqlDataAdapter(SELECT_ALL, CONNECTION_STRING);
//Create and fill DataSet (Select only first 5 rows.).
DataSet rDataSet = new DataSet();
rAdapter.Fill(rDataSet, 0, 5, "Table");
//Modify DataSet.
DataTable rTable = rDataSet.Tables["Table"];
rTable.Rows[0][1] = "new product";
//Add handlers.
rAdapter.RowUpdating += new SqlRowUpdatingEventHandler( OnRowUpdating );
rAdapter.RowUpdated += new SqlRowUpdatedEventHandler( OnRowUpdated );
//Update--this operation fires two events (RowUpdating and RowUpdated) for each changed row.
rAdapter.Update(rDataSet, "Table");
//Remove handlers.
rAdapter.RowUpdating -= new SqlRowUpdatingEventHandler( OnRowUpdating );
rAdapter.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
'Entry point which delegates to C-style main Private Function.
Public Overloads Shared Sub Main()
System.Environment.ExitCode = Main(System.Environment.GetCommandLineArgs())
End Sub
Overloads Public Shared Function Main(args() As String) As Integer
Const CONNECTION_STRING As String = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer"
Const SELECT_ALL As String = "select * from Products"
'Create DataAdapter.
Dim rAdapter As New SqlDataAdapter(SELECT_ALL, CONNECTION_STRING)
'Create and fill DataSet (Select only first 5 rows.).
Dim rDataSet As New DataSet()
rAdapter.Fill(rDataSet, 0, 5, "Table")
'Modify DataSet.
Dim rTable As DataTable = rDataSet.Tables("Table")
rTable.Rows(0)(1) = "new product"
'Add handlers.
AddHandler rAdapter.RowUpdating, AddressOf OnRowUpdating
AddHandler rAdapter.RowUpdated, AddressOf OnRowUpdated
'Update--this operation fires two events (RowUpdating and RowUpdated) for each changed row.
rAdapter.Update(rDataSet, "Table")
'Remove handlers.
RemoveHandler rAdapter.RowUpdating, AddressOf OnRowUpdating
RemoveHandler rAdapter.RowUpdated, AddressOf OnRowUpdated
Return 0
End Function
Overloads Private 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
Overloads Private 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
備註
RowUpdating該事件在一Update行之前舉行。
當你使用 Update時,每更新一列資料會發生兩個事件。 執行順序如下:
中的值 DataRow 會被移到參數值。
便會引發 OnRowUpdating 事件。
指令執行。
若指令設為
FirstReturnedRecord,且第一個回傳結果置於 DataRow。如果有輸出參數,它們會放在 DataRow中。
便會引發 OnRowUpdated 事件。
呼叫 AcceptChanges。
建構函式
| 名稱 | Description |
|---|---|
| SqlRowUpdatingEventArgs(DataRow, IDbCommand, StatementType, DataTableMapping) |
初始化 SqlRowUpdatingEventArgs 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| BaseCommand |
取得或設定 IDbCommand 該類別實例的物件。 (繼承來源 RowUpdatingEventArgs) |
| Command |
執行 時,取得或設定 SqlCommand 執行 Update(DataSet)。 |
| Errors |
當執行 Command 時,會接收 .NET 資料提供者產生的任何錯誤。 (繼承來源 RowUpdatingEventArgs) |
| Row |
會收到 DataRow THE ,作為插入、更新或刪除操作的一部分傳送到伺服器。 (繼承來源 RowUpdatingEventArgs) |
| StatementType |
取得要執行的 SQL 陳述式。 (繼承來源 RowUpdatingEventArgs) |
| Status |
取得或設定 UpdateStatus 該性質的 Command 。 (繼承來源 RowUpdatingEventArgs) |
| TableMapping |
會收到 DataTableMappingUpdate(DataSet)透過 。 (繼承來源 RowUpdatingEventArgs) |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的 物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |