我通过调用存储过程的 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
执行时,报如下错误:
过程没有参数并且提供了参数