Click here to Skip to main content
15,907,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i try this webmethod . HERE vname is varchar

What I have tried:

C#
[WebMethod]
public static string GetVo(string fdate, string tdate, string region)
{
string data2 = "[";
try
{
T1 DB = new T1();
var rea = (from rv in DB.tblRV
join Reg in DB.tblR on rv.RegionID equals Reg.RegionID
join vv in DB.tblVV on rv.ID equals vv.ID
where Reg.Region == region
&& !(vv.VName == "")
&& Reg.StartDate == Convert.ToDateTime(fdate) && Convert.ToDateTime(tdate)
group vv by vv.VName into g
select new
{
Name = g.Key,
cnt = g.Select(t => t.Name).Count()
}).ToList();
data2 += rea.ToList().Select(x => "['" + x.Name + "'," + x.cnt + "]")
.Aggregate((a, b) => a + "," + b);
data2 += "]";
}
catch (Exception ex)
{
throw new Exception();
System.Web.HttpContext currentContext = System.Web.HttpContext.Current;
currentContext.Response.Write("<script>alert('" + currentContext.Server.HtmlEncode(ex.ToString()) + "')</script>");
}
return data2;
}



this shows error

LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' method, and this method cannot be translated into a store expression.
Posted
Updated 23-Jun-16 20:50pm
v7
Comments
Maciej Los 24-Jun-16 2:03am    
What line causes that error?
Karthik_Mahalingam 24-Jun-16 2:43am    
this line seems to be invalid syntax
&& Reg.StartDate == Convert.ToDateTime(fdate) && Convert.ToDateTime(tdate)
what you are checking here..

1 solution

Replace that:
C#
GetVo(string fdate, string tdate, string region)

with
C#
GetVo(DateTime fdate, DateTime tdate, string region)


Above means: use proper data types!

Then improve where statement this way:
C#
where Reg.Region == region && vv.VName != "" && Reg.StartDate >= fdate &&  Reg.StartDate <= tdate
//the rest of your statement here
 
Share this answer
 
v2
Comments
super_user 24-Jun-16 2:49am    
hi when i try this ..
[WebMethod]
public static string GetVo(DateTime fdate, DateTime tdate, string region)
{
string data2 = "[";
try
{


T1 DB = new T1();

var rea = (from rv in DB.tblRV
join Reg in DB.tblRe on rv.RegionID equals Reg.RegionID
join vv in DB.tblVV on rv.ID equals vv.ID

where
Reg.Region==region
&& (vv.VName != "")
&& Reg.StartDate == fdate &&
Reg.EndDate == tdate

group vv by vv.VName into g
select new
{
Name = g.Key,
cnt = g.Select(t => t.Name).Count()
}).ToList();
data2 += rea.ToList().Select(x => "['" + x.Name + "'," + x.cnt + "]")
.Aggregate((a, b) => a + "," + b);
data2 += "]";


}
catch (Exception ex)
{
throw new Exception();
System.Web.HttpContext currentContext = System.Web.HttpContext.Current;
currentContext.Response.Write("<script>alert('" + currentContext.Server.HtmlEncode(ex.ToString()) + "')</script>");
}
return data2;

}

this shows ERROR

Sequence contains no elements
super_user 24-Jun-16 2:52am    
There is drop-down with region names and there is two calendars i place with fromdate and todate ID..


<asp:Label ID="Label3" runat="server" Text="Select Region">
<asp:DropDownList ID="regiondrop" runat="server" AutoPostBack="True"
onselectedindexchanged="regiondrop_SelectedIndexChanged">

<br /><br />

<asp:Label ID="Label1" runat="server" Text="From Date">
<input ID="fromdate" value="dd/mm/yyyy" runat="server" clientidmode="static" />
<br />

<asp:Label ID="Label2" runat="server" Text="To Date">

<input ID="todate" value="dd/mm/yyyy" runat="server" clientidmode="static" />



<br /><br />
<input type="button" ID="search_data" runat="server" class="sear_btn" value="Search Data" />
<br /><br />

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900