【发布时间】:2018-09-14 14:08:11
【问题描述】:
到目前为止,我正在创建两个 sql 命令来运行两个不同的查询。我想知道如果我将运行相同的 sql 命令来执行这两个查询,性能是否会改变
这是我到目前为止的方法
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command1 = new SqlCommand(commandText1, connection))
{
}
using (SqlCommand command2 = new SqlCommand(commandText2, connection))
{
}
// etc
}
方法二
var command = new SqlCommand("<SQL Command>", myConnection);
command.ExecuteNonQuery();
command.CommandText = "<New SQL Command>";
command.ExecuteNonQuery();
性能有什么不同,或者我用什么都没关系。
【问题讨论】:
-
必填链接...Which is faster?
-
相关问题:Reusing SqlCommand?。无论您使用哪种方法。
标签: c#