Databases Reference
In-Depth Information
Conn = new SybaseConnection(
"host=server1;port=4100;User ID=test;Password=test;
Database Name=Accounting");
Conn.Open();
// Open a command object
SybaseCommand salCmd = new SybaseCommand(
"SELECT count(sal) FROM employees" +
"WHERE sal>'50000'", Conn);
try
{
int count = (int)salCmd.ExecuteScalar();
}
catch (Exception ex)
{
// Display exceptions in a message box
MessageBox.Show (ex.Message);
}
// Close the connection
Conn.Close();
Using the Command.Prepare Method
Most applications have a certain set of SQL statements that are executed multiple
times and a few SQL statements that are executed only once or twice during the
life of the application. You may want to use a prepared Command object depending
on how frequently you plan to execute a SQL statement.
Some data providers don't perform an operation with the database when an
application calls Command.Prepare() . These data providers still optimize objects
associated with the Command object on the database client.
A nonprepared Command object is optimized for a SQL statement that is only
executed once. In contrast, a prepared Command object is optimized for SQL
statements that are executed multiple times. Although the overhead for the initial
execution of a prepared Command object is high, the advantage is realized with
subsequent executions of the prepared Command object.
 
Search WWH ::




Custom Search