我正在尝试使用.NET执行UPDATE存储过程。 这是C#部分:
public int spUpdate_Agent(int agentNum, string firstName, string lastNAme, string city, string phone
, string eMail)
{
string cStr = WebConfigurationManager.ConnectionStrings["bgroup33_prodConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(cStr))
{
SqlCommand cmd = new SqlCommand("spUpdate_Agent", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramAgentNum = new SqlParameter("@agentNum", agentNum);
SqlParameter paramAgentFirst = new SqlParameter("@FirstName", firstName);
SqlParameter paramAgentLast = new SqlParameter("@lasttName", lastNAme);
SqlParameter paramAgentCity = new SqlParameter("@city", city);
SqlParameter paramAgentPhone = new SqlParameter("@phone", phone);
SqlParameter paramAgentEmail = new SqlParameter("@eMail", eMail);
cmd.Parameters.Add(paramAgentNum);
cmd.Parameters.Add(paramAgentFirst);
cmd.Parameters.Add(paramAgentLast);
cmd.Parameters.Add(paramAgentCity);
cmd.Parameters.Add(paramAgentPhone);
cmd.Parameters.Add(paramAgentEmail);
try
{
con.Open();
int returenCode = (int)cmd.ExecuteScalar();
return returenCode;
}
catch (Exception ex)
{
return -1;
}
finally
{
con.Close();
}
}
}
这就是存储过程:
alter procedure [dbo].[spUpdate_Agent]
@agentNum int,
@firstName nvarchar(50),
@lasttName nvarchar(50),
@city nvarchar(50),
@phone nvarchar(50),
@eMail nvarchar(50)
as
Begin
update [dbo].[Agent]
set first_name = @firstName,last_name = @lasttName, city = @city,phone = @phone,eMail = @eMail
where agentNum = @agentNum
return 1
end
所以我得到如上所述的这个错误,所有参数都是正确的类型。 那我的问题是什么?