首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SQLCommandBuilder效率

SQLCommandBuilder效率
EN

Stack Overflow用户
提问于 2012-04-19 18:10:30
回答 2查看 1.9K关注 0票数 2

我从msdn MSDN COMMAND BUILDER CLASS上摘录了这篇文章。在ASP.NET中快速插入、更新或删除表是否合适,否则效率会很低吗?!

代码语言:javascript
复制
 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;
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-04-19 18:24:54

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

参考资料:

http://www.dotnetperls.com/sqlparameter

票数 2
EN

Stack Overflow用户

发布于 2012-04-19 18:17:18

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10225910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档