I have SQL query and then i convert this LINQ and then i bind gridview in jquery. Now there is a column in the SQL query with no name.
As you may see in result with "(“no column name)” now i want to give some name this column also how i add this column in code and also in jquery
i have sql query like this
ALTER procedure [dbo].[grid_data]
@fromdate datetime,
@todate datetime,
@region varchar(50)
as
Select D.ID as
ID,
(Select Count(*) from tblve WHERE MID = D.ID and Vme <> '') as
total,
D.lim,
D.Speed
from tblRe M
inner join tblReg D
On M.RID = D.RID
and this return data like this
ID (No column name) lim Speed
19235 3 1065 120
19655 5 923 120
20261 4 757 120
19659 4 551 122
UPDATE
then i convert this to linq like this… now problem is when i add this column “total” then when i press f12 console shows "http://localhost:33578/WebForm1.aspx/search_data Failed to load resource: the server responded with a status of 500 (Internal Server Error)"
[WebMethod]
public static string search_data(DateTime fromdate, DateTime todate, string region)
{
try
{
T1 ts = new T1();
var query = (
from M in ts.tblRe
join D in ts.tblReg on M.RID equals D.RID
where
M.Region == region
&& M.StartDate <= fromdate
&& M.EndDate >= todate
select new {
D.ID,
total= ts.tblve.Where(x => x.MID == D.ID && x.Vme !=
'').Count()
D.lim,
D.Speed
}).ToList();
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("total", typeof(int));
dt.Columns.Add("lim", typeof(string));
dt.Columns.Add("Speed", typeof(string));
foreach (var c in dq)
{
dt.Rows.Add(c.ID,c.total, c.lim, c.Speed);
}
result = DataSetToJSON(dt);
return result;
}
catch (Exception)
{
throw new Exception("");
}
}
and then i add columns and bind gridview in webmethod and in jquery like this
success: function (result) {
var final = JSON.parse(result.d).response;
console.log(JSON.parse(result.d).response)
$("#tabledata").empty();
if (final.length > 0) {
$("#tabledata").append("<tr><th>ID</th><th>total</th><th>lim</th><th>Speed</th></tr>");
for (var i = 0; i < final.length; i++) {
if (final[i] !== null) {
$("#tabledata").append("<tr><td>" +
final[i][0] + "</td> <td>" +
final[i][1] + "</td> <td>" +
final[i][2] + "</td> <td>" +
final[i][3] + "</td></tr>");
}
}
}
}