DB2Error.RowNumber Property
Gets an integer value indicating
the number of the command in the series of chained commands that caused
the error.
This property is valid whenever multiple SQL
statements are executed as part of a single operation. For example,
this property is valid when chaining is active, during a bulk copy
operation, and on Update operations by a DB2DataAdapter.
- Namespace:
IBM.Data.DB2- Assembly:
IBM.Data.DB2(inIBM.Data.DB2.dll)
Syntax
[Visual Basic]
Public ReadOnly Property RowNumber As Integer
[C#]
public int RowNumber {get;}
[C++]
public: __property int get_RowNumber();
[JScript]
public function get RowNumber() : int;
Property value
The number of the statement in the series of chained statements that caused the DB2®Error. For example, a RowNumber value of 2 means that the second statement in the series of chained statements caused the DB2Error. This property is valid when chaining is active (when the DB2Connection.Chaining property is true), and also whenever else multiple SQL statements are executed as part of a single operation.
Example
[Visual Basic, C#] The following example uses chaining to insert 10000 rows into the STAFF table.
[Visual Basic]
Dim con As DB2Connection = new DB2Connection("DATABASE=sample;")
Dim cmd As DB2Command = con.CreateCommand()
con.Open()
' Initialize an insert statement using parameter markers
cmd.CommandText = "INSERT INTO STAFF(ID) VALUES( ? )"
' Add a parameter
Dim p1 As DB2Parameter = cmd.Parameters.Add("@ID", DB2Type.Integer )
' Start the chain
con.BeginChain()
Try
' Loop to add 10000 rows
Dim I As Int32
For I = 1 To 10000
' Set the parameter value
p1.Value = I
' Execute the command.
' Since chaining is active, this statement is now added
' to the chain
cmd.ExecuteNonQuery()
Next I
' Execute the chain
con.EndChain()
Catch db2Ex As DB2Exception
Dim db2Error As DB2Error
' Loop through all the errors
For Each db2Error in db2Ex.Errors
Console.WriteLine("SQLSTATE =" & db2Error.SQLState )
Console.WriteLine("NativeErr=" & db2Error.NativeError )
Console.WriteLine("RowNumber=" & db2Error.RowNumber )
Console.WriteLine( db2Error.Message )
Next DB2Error
Finally
' Explicitly turn chaining off in case it is still on
If (con.Chaining) Then
con.EndChain()
End If
End Try
con.Close()[C#]
DB2Connection con = new DB2Connection("DATABASE=sample;");
DB2Command cmd = con.CreateCommand();
con.Open();
// Initialize an insert statement using parameter markers
cmd.CommandText = "INSERT INTO STAFF(ID) VALUES( ? )";
// Add a parameter
DB2Parameter p1 = cmd.Parameters.Add("@ID", DB2Type.Integer );
// Start the chain
con.BeginChain();
try
{
// Loop to add 10000 rows
for( Int32 i = 1; i <= 10000; i++ )
{
// Set the parameter value
p1.Value = i;
// Execute the command.
// Since chaining is active, this statement is now added
// to the chain
cmd.ExecuteNonQuery();
}
// Execute the chain
con.EndChain();
}
catch( DB2Exception db2Ex )
{
// Loop through all the errors
foreach( DB2Error db2Error in db2Ex.Errors )
{
Console.WriteLine("SQLSTATE =" + db2Error.SQLState );
Console.WriteLine("NativeErr=" + db2Error.NativeError );
Console.WriteLine("RowNumber=" + db2Error.RowNumber );
Console.WriteLine( db2Error.Message );
}
}
finally
{
// Explicitly turn chaining off in case it is still on
if( con.Chaining )
{
con.EndChain();
}
}
con.Close();