hello everyone!
i am trying to use a calendar control. basic function, really. i want to click on a date, query a database for events for which the date is the same, and then display the events.
my problem is that i can't find the way to extract the date from the calendar control to pass it as a parameter to my sqlcommand object.
i set a breakpoint on the SelectionChanged sub, but when i run it, my code never actually stops at that event.
ok, here's some code :
yes, i'm using code-behind. any hints are welcome. thank you !!
Huby.
i am trying to use a calendar control. basic function, really. i want to click on a date, query a database for events for which the date is the same, and then display the events.
my problem is that i can't find the way to extract the date from the calendar control to pass it as a parameter to my sqlcommand object.
i set a breakpoint on the SelectionChanged sub, but when i run it, my code never actually stops at that event.
ok, here's some code :
Code:
private DateTime _dt;
private void Page_Load(object sender, System.EventArgs e)
{
//on first execution, we just use today's date
if (!this.IsPostBack)
{
_dt = DateTime.Now;
}
LoadEvents();
}
private void LoadEvents()
{
string strSQL = "Select * from Events WHERE eventStartDate = @date order by eventStartDate asc";
SqlConnection conn = new SqlConnection(myConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand(strSQL,conn);
SqlParameter prm = new SqlParameter();
prm.SqlDbType = SqlDbType.DateTime;
prm.Size=8;
prm.ParameterName = "@date";
prm.Value = _dt;
cmd.Parameters.Add(prm);
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{
Response.Write(dr["eventTitle"]);
}
dr.Close();
conn.Close();
}
private void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
// this code is never executed ... is it in the wrong event ?
_dt = Calendar1.SelectedDate;
}
yes, i'm using code-behind. any hints are welcome. thank you !!
Huby.