Wednesday, April 13, 2005

RECORD COUNT ADO.NET, C#

Moojjoo Blog

THE FOLLOWING CODE IS FOR COUNTING RECORDS IN A DATABASE USING ADO.NET, C#

//string countSQL = "SELECT COUNT(userID) FROM CamelHeadCount WHERE userID =" + GetUserName();
string countSQL = "SELECT COUNT(userID) FROM CamelHeadCount WHERE userID = 'DANNELR'";
SqlConnection Conn = new SqlConnection(strConn);
SqlCommand myCommand = new SqlCommand(countSQL, Conn);

Conn.Open();
Int32 recordCount = (Int32) myCommand.ExecuteScalar();

if (recordCount > 0)
{
Response.Write("Our records indicate that you have already confirmed");
Response.End();
}
Conn.Close();
Post a Comment