错误:另一个SQLParameterCollection已包含SqlParameter. [英] Error : The SqlParameter is already contained by another SqlParameterCollection.

查看:85
本文介绍了错误:另一个SQLParameterCollection已包含SqlParameter.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void UpdateUserStatus(string CollectionUserId, string CollectionStatus, int CountDisabled, int CountEnalbed, int companyId)
        {
            try
            {
                string[] individualStatus = CollectionStatus.Split(',');
                string[] individualUserid = CollectionUserId.Split(',');
                  for (int i = 0; i < individualStatus.Length; i++)
                  {
                    DbParams dbParams = new DbParams();
                    dbParams.Add<int>("UserID", Convert.ToInt32(individualUserid[i]));
                    dbParams.Add<int>("Status",Convert.ToInt32(individualStatus[i]));
                    DataContext.ExecuteProc(DbNames.UPDATE_USERSTATUS, dbParams);




                if (CountEnalbed != 0 || CountDisabled != 0)
                {
                    dbParams.Add<int>("UserID",Convert.ToInt32(individualUserid[i]));
                    dbParams.Add<int>("Status",Convert.ToInt32(individualStatus[i]));
                    dbParams.Add<int>("CompanyID",CompanyID);
                    DataContext.ExecuteProc(DbNames.INSERT_MEMBER_TRANSACTION, dbParams); // Error : The SqlParameter is already contained by another SqlParameterCollection.

                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

帮我.这是我第一次看到它的期望,我对goion在...上的困惑感到困惑.

help me.here is expection i saw it first time and i m confused whts goion on...

Error : The SqlParameter is already contained by another SqlParameterCollection.

推荐答案

您的参数只能由一个查询使用.因此,在if块中,您应该创建一个新的DbParams并填充并使用该DbParams或清除您的参数.
许多人和您有同样的问题.就像此人 [这些 [ ^ ]个人.
祝你好运!
Your parameters can only be used by one query. So in the if block you should create a new DbParams and fill and use that one instead or clear your parameters.
Many people have the same problem as you. Like this person[^] or these[^] people.
Good luck!


这篇关于错误:另一个SQLParameterCollection已包含SqlParameter.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆