-2

我通过调用存储过程的 c# 代码在 sql 表中插入行。

C#代码:

SqlCommand myCommand = thisConnection.CreateCommand();
                myCommand.CommandText = "FederationUpdateCTRAndImpressionCountsForAllYPIds";
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.Parameters.Add("@bid", SqlDbType.UniqueIdentifier);
                myCommand.Parameters.Add("@uid", SqlDbType.UniqueIdentifier);
                myCommand.Parameters.Add("@imp", SqlDbType.VarChar);
                myCommand.Parameters.Add("@ctr", SqlDbType.VarChar);

                while (myfederationReader.Read())
                {                      
                    myCommand.Parameters["@bid"].Value = myfederationReader["BusinessId"];
                    myCommand.Parameters["@uid"].Value = myfederationReader["UId"];
                    myCommand.Parameters["@imp"].Value = myfederationReader["Impression"];
                    myCommand.Parameters["@ctr"].Value = myfederationReader["CTR"];                    
                    rowsAffected = myCommand.ExecuteNonQuery();                        
                }

存储过程:

CREATE PROCEDURE [dbo].[FederationUpdateCTRAndImpressionCountsForAllYPIds]
    @bid uniqueidentifier,
    @uid uniqueidentifier,
    @imp varchar(255),
    @ctr varchar(255)
AS  BEGIN   
    UPDATE  BasicBusinessInformation
    SET     BasicBusinessInformation.CTR = @ctr , BasicBusinessInformation.Impression = @imp
    WHERE   BasicBusinessInformation.BusinessId = @bid AND  BasicBusinessInformation.UId = @uid 
    END

执行时,报如下错误:

过程没有参数并且提供了参数

4

3 回答 3

2

尝试清除命令参数

[C#] 
public bool ExportAndClear() {
SqlParameter[] myParamArray = new SqlParameter[myCmd.Parameters.Count - 1];
myCmd.Parameters.CopyTo(myParamArray, 0);
myCmd.Parameters.Clear();
return true;
}
于 2013-06-10T12:49:49.310 回答
0

在触发此命令之前尝试从阅读器获取数据

1)Fetch data from reader and store in list or datatable
2)For loop on list or datatable
3)in for loop fire this command
于 2013-06-10T13:01:20.160 回答
-3

尝试移动以下

SqlCommand myCommand = thisConnection.CreateCommand();
                myCommand.CommandText = "FederationUpdateCTAndImpressionCountsForAllYPIds";
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.Parameters.Add("@bid", SqlDbType.UniqueIdentifier);
                myCommand.Parameters.Add("@uid", SqlDbType.UniqueIdentifier);
                myCommand.Parameters.Add("@imp", SqlDbType.VarChar);
                myCommand.Parameters.Add("@ctr", SqlDbType.VarChar);

在while循环中,看看你是否得到不同的结果。

于 2013-06-10T12:47:34.660 回答