C#SQL数据适配器-如果查询响应超过某一行长度,则限制填充大小
给定以下使用查询数据填充DataTable对象的代码:C#SQL数据适配器-如果查询响应超过某一行长度,则限制填充大小,c#,performance,dataadapter,C#,Performance,Dataadapter,给定以下使用查询数据填充DataTable对象的代码: var response = new DataTable(); using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand sqlCommand = new SqlCommand(query, connection); sqlCommand.CommandTimeout
var response = new DataTable();
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
SqlCommand sqlCommand = new SqlCommand(query, connection);
sqlCommand.CommandTimeout = 30;
SqlDataAdapter da = new SqlDataAdapter(sqlCommand);
da.Fill(response);
connection.Close();
da.Dispose();
}
假设通过此代码发送任何查询
如果查询返回涉及数GB数据的数万行,则可能存在性能问题。是否有办法更改“Fill”命令,使其仅填充前1000行,并在之后停止接受数据
当前,当返回较大的查询时,会占用较大的堆空间(图中显示了填充前后的快照),我正在寻找一种只以编程方式填充一定数量的方法
这可能吗?修改查询以仅选择前1000个records@TimSchmelter我正在编写一个允许任何查询通过的接口。您是否要求我以编程方式添加“select top 1000(查询)”是的,您可以选择select top 1000,但您最好向我们展示查询,同时确保在查询中只选择所需的列,如果您知道自己的条件,还可以更好地查看索引和运行SQL执行计划,这意味着根据where子句选择它,这将是更为理想的。。请显示查询,一般来说,我不允许这样做,因为这是许多问题的根源,不仅与性能有关,还有这种过载