c#查询数据库时读取数据不读取第一的数据
您可以使用OFFSET和FETCH子句来跳过第一行并读取余下的数据。例如:
string connectionString = "your_connection_string";
string query = "SELECT * FROM your_table ORDER BY your_column OFFSET 1 ROWS FETCH NEXT " + (rowCount - 1) + " ROWS ONLY";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(query, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
// 读取数据
}
}
在这里,OFFSET 1 ROWS将跳过第一行,FETCH NEXT将返回余下的数据行。请替换your_connection_string,your_table,your_column和rowCount以适应您的情况
原文地址: https://www.cveoy.top/t/topic/c1kr 著作权归作者所有。请勿转载和采集!