【问题标题】:SQLCommandBuilder EfficiencySQLCommandBuilder 效率
【发布时间】:2012-04-30 20:09:09
【问题描述】:

我从 msdn 得到这个摘录 MSDN COMMAND BUILDER CLASS .在 ASP.NET 中使用快速插入、更新或从表中删除是否可以,还是效率低下?!

 public static DataSet SelectSqlRows(string connectionString, string queryString, string tableName)
{
    using (SqlConnection connection = new SqlConnection(connectionString))
    {


        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(queryString, connection);
        SqlCommandBuilder builder = new SqlCommandBuilder(adapter);

        connection.Open();

        DataSet dataSet = new DataSet();
        adapter.Fill(dataSet, tableName);

        //code to modify data in DataSet here

        builder.GetUpdateCommand();

       //Without the SqlCommandBuilder this line would fail
       adapter.Update(dataSet, tableName);

       return dataSet;
    }
}

【问题讨论】:

    标签: c# asp.net sql .net ado.net


    【解决方案1】:

    它将与您执行的底层 SQL 语句一样高效。

    【讨论】:

      【解决方案2】:

      您的代码没有关于效率的问题。一种建议是使用存储过程或参数化查询,而不是直接执行查询字符串,这将有助于防止 SQL 注入。

      参考:

      http://www.dotnetperls.com/sqlparameter

      【讨论】:

        猜你喜欢
        • 2011-10-17
        • 2011-05-28
        • 2013-08-23
        • 2012-04-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-22
        相关资源
        最近更新 更多