This is a migrated thread and some comments may be shown as answers.

RadDatePicker with SqlQuery gives conversion error

2 Answers 37 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sucheta Patil
Top achievements
Rank 1
Sucheta Patil asked on 13 Oct 2010, 04:30 PM
hi
Below is my sql query whose output I intend to bind to RadGrid1.
But I get error on DateTime field ExpectedDate which is a RadDatePicker.

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime

My code is
string strSql = "Select 'Visitor''s Name'=VisitorsName,'Organisation'=VisitorsOrg ,
'Due at' =Arriving_at_hr+':'+Arriving_at_mm, 'Visiting'=Name, Faculty=Short_name , School=School ,
'Call Ext'=Extension,'Meeting room'=RoomNo,'Send to Room'=Send_to_room,Comments
from tblVisitors,tblservice where tblvisitors.Division=tblService.Faculty_Name and Centre='" + lstCentre.SelectedItem.Value + "'
and ExpectedDate = convert(varchar(50),'" + txtOnDate.SelectedDate.Value + "', 101) Order by Name";
          

Any quick help is appreciable!!!
I had to come up with this coz no one replied me for
http://www.telerik.com/community/forums/aspnet-ajax/general-discussions/linq-where-clause-in-aspx-with-datetime-does-not-work.aspx

Please this is not solved either!!!!
S

2 Answers, 1 is accepted

Sort by
0
Accepted
Radoslav
Telerik team
answered on 19 Oct 2010, 09:28 AM
Hello Sucheta,

To achieve the desired functionality you could try using the following approach:
Remove the DateTime.Parse from LinqDataSource's Where clause and remove the WhereParameters:
<asp:LinqDataSource ID="LinqVisitors" runat="server" ContextTypeName="CWC.Staffnet.Forms.StaffnetDataContext" TableName="tblVisitors" 
Where="Centre == @Centre && ExpectedDate == @ExpectedDate" onselecting="LinqVisitors_Selecting">
</asp:LinqDataSource>

On txtOnDate_SelectedDateChanged event handler add explicitly Parameter to the LinqVisitors.WhereParameters with DefaultValue equals to txtOnDate.SelectedDate:
void txtOnDate_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
{
   Parameter p = new Parameter();
   p.Name = "ExpectedDate";
   p.Type=TypeCode.DateTime;
   p.DefaultValue = txtOnDate.SelectedDate.ToString();
   LinqVisitors.WhereParameters.Add(p);
}

Additionally I am sending you a simple example which demonstrates the described approach. Please check it out and let me know if it helps you.

Kind regards,
Radoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sucheta Patil
Top achievements
Rank 1
answered on 19 Oct 2010, 11:10 AM
Hi Radoslav,
        Thanks for the help.I figured it out myself as I had to submit it quickly.
Thanks anyways,

Sucheta
Tags
General Discussions
Asked by
Sucheta Patil
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Sucheta Patil
Top achievements
Rank 1
Share this question
or