Just pass the Calendar1.SelectedDate which is a DateTime value to the sql query, but use parameterized query to prevent
Preventing SQL Injection Attack ASP.NET - Part I[
^]
The code snippet:
DateTime startDate = Calendar1.SelectedDate;
DateTime endtDate = Calendar2.SelectedDate;
string commandText = "select sum(column) from tablename where datecolumn between @startDate and @enddate";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(commandText, connection);
command.Parameters.AddWithValue("@startDate", startDate);
command.Parameters.AddWithValue("@endDate", endDate);
Int32 sum = (Int32) command.ExecuteScalar();
Textbox1.Text = sum.ToString();
}
Refer:
1.
Calendar.SelectedDate Property[
^]
2.
SqlCommand.Parameters Property[
^]