I'm doing a little app where a user enters a block of queries and then executes them.
The thing is that I want to show relevant information, like for example if he inputs something like:
SELECT * FROM server;
UPDATE server SET name = 'Kojak';
It gets:
- The rows selected
- The number of rows affected by the UPDATE
My printing loop looks like:
reader = cmd.ExecuteReader();
do
{
while (reader.Read())
{
if (!(reader.RecordsAffected > 0))
{
for (int i = 0; i < reader.FieldCount; i++)
host.WriteLine("Field " + i + ": " + reader[i].ToString());
}
else {
host.WriteLine(reader.RecordsAffected.ToString() + " Affected rows.");
}
}
} while (reader.NextResult());
host.WriteLine("Block executed successfuly");
The thing is that I can't manage to make the difference between SELECTs and UPDATEs, because reader.Read() returns FALSE when it reaches the second query. How can I solve that and be able to get the number of affected rows when there's a UPDATE/DELETE/INSERT query ?
Thanks.