惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - 笨笨丁

IIS启用兼容模式设置(win2k3—Win7) C#调用java类、jar包方法(转) 解决VML遭遇IE8和XHTML DOCTYPE时不能运行的问题(转) Nice Validator(Form验证)及Juery zTree控件 ASP.NET程序中 抛出"Thread was being aborted. "异常(转) SQL语句Where中使用别名作为判断条件 50个令人惊奇的jQuery插件(对话框和表单篇)及免费的响应式bootstrap管理员后台界面主题 - Charisma PowerDesigner设计时表显示注释选项 showModalDialog 的重要提示 在网页中怎样给已发布的Flash添加链接的方法(zhuan) ASP.NET网站中获取当前虚拟目录的应用程序目录的方法(转) __doPostBack()没有定义解决方法(转) jQuery插件实战之fullcalendar(日历插件) - 使用fullcalendar开发一个功能完整的富客户端会议室预定系统(转) ajaxpro返回值类型总结-DataTable(转) jQuery校验validate详解(转) 一个.NET通用JSON解析/构建类的实现(c#)转 C# JSON字符串序列化与反序列化(转) AjaxPro新发现-错误处理 SVN专题:SVN Client API的.net 接口 SharpSvn介紹 Checkout操作实例,SVN权限(转)
Ibatis.net总是报:【ExecuteStoreCommand SqlParameterCollection 中已包含 SqlParameter】(转)
笨笨丁 · 2013-07-13 · via 博客园 - 笨笨丁

今天很奇怪调用EF的ExecuteStoreCommand 出现了个这样的错误,怎么也调试不过,痛定思痛

原来 command被连着调用了而没有销毁掉

public static DataTable GetDataTable(
            string connDBStr, string sql, params SqlParameter[] cmdParms)
        {
            SqlCommand cmd = new SqlCommand();
            using (SqlConnection conn = new SqlConnection(connDBStr))
            {
                PrepareSqlCommand(cmd, conn, null, sql, cmdParms);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable    (SetSqlAsDataTableName(sql));
                da.Fill(dt);
                cmd.Parameters.Clear();//多了这一句,就解决了问题
                return dt;
            }

        }

还要说说EF调用 ExecuteStoreCommand 的用法

string orderCode =“test1”;

string dishMenuCode=“test2”

          var parameter = new SqlParameter[]{

  new SqlParameter("@p_order",orderCode),
                    new SqlParameter("@p_dish",dishMenuCode),
                };//多个参数的列子
               

ef.ExecuteStoreCommand("update dbo.order_info_ed set dpState='1' where orderCode=@p_order and dishMenuCode=@p_dish", parameter);

                var paramenter2 = new SqlParameter { ParameterName = "@p_user", Value = "gxw" };//一个参数的例子
                ef.ExecuteStoreCommand("select * From UserTable where username=@p_user", paramenter2);