Databases Reference
In-Depth Information
" Salary: " + dataReader.GetInt32(2));
}
System.Console.WriteLine();
// Close the DataReader
dataReader.Close();
// Prepare the UPDATE statement for multiple executions
transaction = conn.BeginTransaction();
sql = "UPDATE employees SET salary = salary * 1.05" +
"WHERE id=?";
cmd.CommandText = sql;
cmd.Prepare();
// Execute the UPDATE statement for each
// value of index between 0 and 9
for (int index = 0; index < 10; index++) {
cmd.Parameters[0].Value = index;
cmd.ExecuteNonQuery();
}
// Manual commit
transaction.Commit();
// Execute a SELECT statement. A prepare is unnecessary
// because it's only executed once.
sql = "SELECT id, name, salary FROM employees";
cmd.CommandText = sql;
// Fetch the data
dataReader = cmd.ExecuteReader();
while (dataReader.Read()) {
System.Console.WriteLine("Id: " + dataReader.GetInt32(0) +
" Name: " + dataReader.GetString(1) +
Search WWH ::




Custom Search