简体   繁体   English

SQLDataAdapter Fill方法如何触发数据库查询?

[英]How SQLDataAdapter Fill method fires Database Queries?

I have a query in understanding the SQLDataAdapter fill method,which takes arguments like startRecord,MaxRecord as shown below - 我在了解SQLDataAdapter填充方法时遇到了一个查询,该方法采用类似startRecord,MaxRecord的参数,如下所示-

SqlDataAdapter adap = new SqlDataAdapter ("Select * from tblname",ConnectionString);
DataSet ds = new DataSet();
adap.Fill(ds, startIndex, MaxRecords , "TableName");

I want to know what will the SqlDataAdapter do. 我想知道SqlDataAdapter会做什么。

Will it first fire the query that would bring back entire record from the table and then filer the rows from it ? 它是否会首先触发查询,该查询将从表中带回整个记录,然后对表中的行进行过滤?

or 要么

Will it fire a query in the database that would select only the required amount of rows ? 是否会在数据库中触发只选择所需行数的查询?

SqlDataAdapter serves as a bridge with DataSet and SQL Server for retrieving and saving data. SqlDataAdapter充当与DataSet和SQL Server的桥梁,用于检索和保存数据。 When the SqlDataAdapter fills a DataSet, it will create the necessary tables and columns for the returned data if they do not already exist. 当SqlDataAdapter填充数据集时,它将为返回的数据创建必要的表和列(如果尚不存在)。

This is segment of code to make you understand better 这是一段代码,可以使您更好地理解

string sqlStatement = "Select * from tblname ";
                SqlCommand cmd = new SqlCommand(sqlStatement, con);
                DataSet ds = new DataSet();

                SqlDataAdapter adap = new SqlDataAdapter(cmd);
                cmd.ExecuteNonQuery();
                adap.Fill(ds);

sqlDataAdapter.Fill(dataSet, currentIndex, pageSize, "TableName"); will query for the whole result set and then page them in memory. 将查询整个结果集,然后将其分页到内存中。

For large result sets this is not what you want. 对于大型结果集,这不是您想要的。 If you want the paging to happen on the server use the SKIP and TOP clause in the SQL you use. 如果要在服务器上进行分页,请在所用SQL中使用SKIP和TOP子句。

Here is the documentation which explains this. 是解释此问题的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM