Databases Reference
In-Depth Information
// execute nonquery to insert an employee
Console.WriteLine(
"Executing statement {0}"
, cmdnon.CommandText
);
cmdnon.ExecuteNonQuery();
Console.WriteLine(
"After INSERT: Number of employees {0}\n"
, cmdqry.ExecuteScalar()
);
// execute nonquery to delete an employee
cmdnon.CommandText = sqldel;
Console.WriteLine(
"Executing statement {0}"
, cmdnon.CommandText
);
cmdnon.ExecuteNonQuery();
Console.WriteLine(
"After DELETE: Number of employees {0}\n"
, cmdqry.ExecuteScalar()
);
}
catch (SqlException ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
conn.Close();
Console.WriteLine("Connection Closed.");
}
}
}
}
3. Make CommandNonQuery the startup project, and then run it by pressing
Ctrl+F5. You should see the results in Figure 11-6.
Search WWH ::




Custom Search