2016-12-28 42 views
0

我創建一個web應用程序中,我有6000員工,我想顯示在一個表中的所有員工在我的web應用程序,選擇的記錄數顯示MVC 5

記錄數量非常大這就是爲什麼它正在採取太多的時間給我看數據

這裏是我的web服務

 [WebMethod] 
     [ScriptMethod(UseHttpGet = true)] 
     public void showrecd() 
     { 
      List<object> employeedata = new List<object>(); 
      SqlCommand cmd = new SqlCommand("select * from dbo.employeedetails order by id desc",con); 
      con.Open(); 
      SqlDataReader dr = cmd.ExecuteReader(); 
      while(dr.Read()) 
      { 
       employeedata.Add(new{ 
        id=dr["id"].ToString(), 
        empname=dr["empname"].ToString(), 
        address = dr["address"].ToString(), 
        jobdescrib =dr["jobdescrib"].ToString(), 
        brandname=dr["brandname"].ToString(), 
        location=dr["location"].ToString() 
       }); 
      } 
      var json = js.Serialize(employeedata); 
      Context.Response.Write("{" + '"' + "info" + '"' + ":" + json + "}"); 
      con.Close(); 
     } 

從我在這裏獲取數據的,

現在IW螞蟻,使工作更容易,我已經採取了文本框

<input type="text" ng-model="records" ng-change="showrecordsasperthistextbox()"/> 

,如果現在如果用戶在上面的文本框中輸入(500),只有500個記錄必須由Web服務 進賬,如果用戶輸入(1 )只有一個記錄應該由web服務獲取,

我需要做什麼和如何?

+0

用於函數'showrecordsasperthistextbox()'的代碼是什麼? – Viki888

+0

使用數據表,它將提供所有功能搜索/過濾/分頁等。 –

+0

傳遞用戶輸入值以將查詢選擇爲參數。並將其附加在「TOP」條款中。 '從dbo.employeedetails中選擇TOP(@ P1)* id desc' –

回答

2

讓我們聲明INT

Int number=20;//Declare this dynamic 
SqlCommand cmd = new SqlCommand("select top (cast('"+number+"' as int)) * from dbo.employeedetails order by id",con); 

,現在你的SqlCommand

//如果你得到錯誤(top('"+number+"'))此命令

試試這個

(cast('"+number+"' as int)) 

讓我知道