It seems like you didn't provided the right datetime range to the query. Just validate the datetime input textboxs and you should be fine.
[EDITED]
Perhaps this can be helpful.
try
{
SqlConnection MAconn = new SqlConnection();
MAconn.ConnectionString = connectionString;
MAconn.Open();
SqlCommand MAcmd = MAconn.CreateCommand();
DateTime startDate, endDate;
DateTime.TryParse(TextBox1.Text, out startDate);
DateTime.TryParse(TextBox2.Text, out endDate);
if (startDate != null && endDate != null && !string.IsNullOrEmpty(startDate.ToString()) && !string.IsNullOrEmpty(endDate.ToString()) && endDate.CompareTo(startDate) >= 0)
{
MAcmd.CommandText = "select Sum(price) from sale where startdate between @startDate and @endDate";
MAcmd.Parameters.AddWithValue("@startDate", startDate.ToString());
MAcmd.Parameters.AddWithValue("@endDate", endDate.ToString());
lblsale.Text = System.Convert.ToString(MAcmd.ExecuteScalar());
}
else
lblres.Text = "oh date entered is not in range";
MAconn.Close();
}
catch (Exception ex)
{
lblres.Text = "oh date entered is not in range" + ex;
}