是否总是需要数据适配器?
Is a Data Adapter always needed?
如果有一个我只想执行的查询,并且不需要在 table 中填充任何数据,那么是否有必要为此目的使用数据适配器?
不,没有必要使用 SqlDataAdapter。它实际上是数据集和 Sql 服务器之间的桥梁。
您可以使用 SqlCommand - ExecuteNonQuery.
You can use the ExecuteNonQuery to perform catalog operations (for
example, querying the structure of a database or creating database
objects such as tables), or to change the data in a database without
using a DataSet by executing UPDATE, INSERT, or DELETE statements.
Although the ExecuteNonQuery returns no rows, any output parameters or
return values mapped to parameters are populated with data.
using (SqlConnection conn = new SqlConnection(
"your connection string"))
{
using (SqlCommand command = new SqlCommand("your sql", conn)
{
conn.Open();
command.ExecuteNonQuery();
}
}
如果有一个我只想执行的查询,并且不需要在 table 中填充任何数据,那么是否有必要为此目的使用数据适配器?
不,没有必要使用 SqlDataAdapter。它实际上是数据集和 Sql 服务器之间的桥梁。
您可以使用 SqlCommand - ExecuteNonQuery.
You can use the ExecuteNonQuery to perform catalog operations (for example, querying the structure of a database or creating database objects such as tables), or to change the data in a database without using a DataSet by executing UPDATE, INSERT, or DELETE statements. Although the ExecuteNonQuery returns no rows, any output parameters or return values mapped to parameters are populated with data.
using (SqlConnection conn = new SqlConnection(
"your connection string"))
{
using (SqlCommand command = new SqlCommand("your sql", conn)
{
conn.Open();
command.ExecuteNonQuery();
}
}