11
Answers

Return dataset in linq

scropio gurl

scropio gurl

8y
469
1

i try to return data in web method using linq .. and also i bind grid view in jquery

  1. $(document).ready(function () {  
  2.          BindGridView();  
  3.   
  4.      });  
  5.      function BindGridView() {  
  6.          $.ajax({  
  7.              type: "POST",  
  8.              url: "WebForm1.aspx/search_data",  
  9.              data: JSON.stingify(obj),  
  10.              data: "{'fromdate':'" + fromdate + "','todate':'" + todate + "','regiondrop':'" + regiondrop + "','GridView1':'" + GridView1 + "'}",  
  11.              contentType: "application/json; charset=utf-8",  
  12.              dataType: "json",  
  13.              async: true,  
  14.              cache: false,  
  15.              success: function (result) {  
  16.                  $("#GridView1").empty();  
  17.                  if (data.d.length > 0) {  
  18.                      $("#GridView1").append(  
  19.                  "<tr><th>Owner Name</th><th>Reg No</th></tr>");  
  20.   
  21.                      for (var i = 0; i < data.d.length; i++) {  
  22.                          $("#GridView1").append("<tr><td>" +  
  23.                  data.d[i].OwnerName + "</td> <td>" +  
  24.                  data.d[i].RegNo + "</td> <td>" +  
  25.                    
  26.                      }  
  27.                  }  
  28.              }  
  29.          });  
  30.      }  

webmethod

  1. [WebMethod]  
  2.         public static string search_data(DateTime fromdate, DateTime todate, string regiondrop)  
  3.         {  
  4.   
  5.             try  
  6.             {  
  7.                 TrackDataEntities1 ts = new TrackDataEntities1();  
  8.                   
  9.                 var dq = from table //here is LINQ query which is long so i did not paste .....     .ToList();  
  10.                 
                 DataSet ds = new DataSet();
                 dq(ds);
                 return ds;
     
  11.   
  12.   
  13.             }  
  14.             catch (Exception)  
  15.             {  
  16.                 throw new Exception();  
  17.                 // GridView1.Visible = false;  
  18.                 // Label4.Text = ("No Data");  
  19.   
  20.             }  
  21.   
  22.         }  
this show error
Error 3 'dq' is a 'variable' but is used like a 'method'
Error 4 Cannot implicitly convert type 'System.Data.DataSet' to 'string'

so how i return this


Answers (11)