DB2®Connection.Chaining Property
Gets a boolean value indicating if chaining is active.
- Namespace:
IBM.Data.DB2
- Assembly:
IBM.Data.DB2
(inIBM.Data.DB2.dll
)
Syntax
[Visual Basic]
Public ReadOnly Property Chaining As Boolean
[C#]
public bool Chaining {get;}
[C++]
public: __property bool get_Chaining();
[JScript]
public function get Chaining() : Boolean;
Property value
True if chaining is active. Chaining is active for a DB2Connection object if the application has called that object's BeginChain method, but has not yet called its EndChain method.
False if chaining is not active.
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();