ExecuteNext(IDataReader) Method
On this page
Executes the next statement from the script.
Syntax
Parameters
- reader
- DbDataReaderBase to store result set.
Return Value
true if there are more statements to execute; otherwise, false.
Example
This sample demonstrates how to execute script and retrieve information about how many records were affected by a statement. For statements that return a result set the first column is written to console.
|
|---|
string script =
"INSERT INTO DEPT VALUES (10,'ACCOUNTING','NEW YORK');"+
"INSERT INTO DEPT VALUES (20,'RESEARCH','DALLAS');"+
"INSERT INTO DEPT VALUES (30,'SALES','CHICAGO');"+
"INSERT INTO DEPT VALUES (40,'OPERATIONS','BOSTON');"+
"SELECT * FROM DEPT";
DB2Connection dB2Conn = new DB2Connection(
"user id=db2admin;server=db2;database=SAMPLE;");
DB2Script dB2Script = new DB2Script(script,dB2Conn);
IDataReader dB2Reader;
dB2Conn.Open();
while (dB2Script.ExecuteNext(out dB2Reader))
{
Console.WriteLine("Records affected " + dB2Reader.RecordsAffected);
while (dB2Reader.Read())
{
Console.WriteLine(dB2Reader.GetString(0));
}
dB2Reader.Close();
}
dB2Conn.Close(); |
|
|---|
Dim script As String = _
"INSERT INTO DEPT VALUES (10,'ACCOUNTING','NEW YORK');" & _
"INSERT INTO DEPT VALUES (20,'RESEARCH','DALLAS');" & _
"INSERT INTO DEPT VALUES (30,'SALES','CHICAGO');" & _
"INSERT INTO DEPT VALUES (40,'OPERATIONS','BOSTON');" & _
"SELECT * FROM DEPT"
Dim dB2Conn As DB2Connection = New DB2Connection( _
"user id=db2admin;server=db2;database=SAMPLE;")
Dim dB2Script As DB2Script = New DB2Script(script, dB2Conn)
Dim dB2Reader As IDataReader
dB2Conn.Open()
While (dB2Script.ExecuteNext(dB2Reader))
Console.WriteLine("Records affected " & dB2Reader.RecordsAffected)
While dB2Reader.Read()
Console.WriteLine(dB2Reader.GetString(0))
End While
dB2Reader.Close()
End While
dB2Conn.Close() |
See Also