I have a function that opens the database and returns the highest id, I have been using executescalar as there is only one value to return.
The problem is though if there is nothing in the database then it crashes. is there a way to determine if there is anything there before I executescalar?

here is the code
<code>

//open the database and return the most recent alertid
System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
connection.Open();
string commandString = "SELECT MAX(AlertId) FROM Alert";
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
command.CommandText = commandString;
command.Connection = connection;

int alertid = (int) command.ExecuteScalar();

//Release all resources
connection.Close();
command.Dispose();

//return the id of the largest alert
return(Convert.ToInt16(alertid));

</code>