Reputation: 269
I got a error when I do the follow:
DateFrom
has as datatype of datetime
My C# code:
string strQuery = "Select * FROM Agenda Where DateFrom='" + Calendar1.SelectedDate.Date.Date + "' ";
SqlCommand command = new SqlCommand(strQuery, Global.myConn);
da = new SqlDataAdapter(command);
da.Fill(Global.dsAgenda, "Tabel");
ddlActivity.DataSource = Global.dtAgenda;
ddlActivity.DataBind();
Calendar1 type:
Error:
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
Upvotes: 0
Views: 513
Reputation: 11606
You should prefer using parameters
:
string strQuery = "SELECT * FROM Agenda WHERE DateFrom = @Date";
SqlCommand command = new SqlCommand(strQuery, Global.myConn);
command.Parameters.Add("@Date", SqlDbType.DateTime).Value = Calendar1.SelectedDate;
Upvotes: 4