Home | Articles|Namespace|Interview Questions|Tools|Jobs|Projects|Community
Asp.net Tutorials

»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books

»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects

»Competition
Community
Winners
Prizes
Write For Us
Members

»Other Resources
Links
Dotnet Resources


Forums»C# .NET »



Retrieving a single value from a database

Run your stored proc or query and then use the SqlCommand object to call the ExecuteScalar method. This method will return a single value.

//conn is your SqlConnection

SqlCommand cmd = new SqlCommand(("select count(*) from Items", conn);

int items = (int)cmd.ExecuteScalar(); //will return an integer value

posted by:Nathan  on 5/2/2007 12:00:00 AM
© 2008 dotnetwatch.com -- Privacy policy

Website Design & Internet Marketing by Shivam