ADO.net ExecuteScalar

Go back to: Code Samples
// Open a connection to the database
SybaseConnection Conn;
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();




Like what you see? Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis

Book Content Copyright © 2009 by Prentice Hall PTR. All rights reserved. | Corporate Sponsor DataDirect Technologies.