select 显示 mvc 5 的记录数
select the number of records to show mvc 5
我正在创建一个网络应用程序,其中有 6000
名员工,我想在我的网络应用程序 table 上显示所有员工,
记录数量非常多,这就是为什么要花太多时间来显示数据的原因
这是我的网络服务
[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();
}
我正在从这里获取数据,
现在我想让工作更轻松,我拿了一个文本框
<input type="text" ng-model="records" ng-change="showrecordsasperthistextbox()"/>
现在如果用户在上面的文本框中输入 (500),web 服务只需要获取 500 条记录
如果用户输入 (1),网络服务只应获取一条记录,
我需要做什么以及如何做???
让我们声明一个 int
Int number=20;// Declare this as dynamic
SqlCommand cmd = new SqlCommand("select top (cast('" + number + "' as int)) * from dbo.employeedetails order by id",con);
现在是你的 sql 命令
//如果您在 (top('"+number+"'))
此命令中遇到错误
试试这个
(cast('"+number+"' as int))
告诉我
我正在创建一个网络应用程序,其中有 6000
名员工,我想在我的网络应用程序 table 上显示所有员工,
记录数量非常多,这就是为什么要花太多时间来显示数据的原因
这是我的网络服务
[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();
}
我正在从这里获取数据,
现在我想让工作更轻松,我拿了一个文本框
<input type="text" ng-model="records" ng-change="showrecordsasperthistextbox()"/>
现在如果用户在上面的文本框中输入 (500),web 服务只需要获取 500 条记录 如果用户输入 (1),网络服务只应获取一条记录,
我需要做什么以及如何做???
让我们声明一个 int
Int number=20;// Declare this as dynamic
SqlCommand cmd = new SqlCommand("select top (cast('" + number + "' as int)) * from dbo.employeedetails order by id",con);
现在是你的 sql 命令
//如果您在 (top('"+number+"'))
此命令中遇到错误
试试这个
(cast('"+number+"' as int))
告诉我