我正在运行更新查询,它说没有找到第二个参数(状态),尽管我明确发送它。它们位于不同的类中,并由一个按钮调用,该按钮发送邮件,然后在主表中更改变量(statusRef)的值(此字段是新的)。
protected void sendMail(object sender, EventArgs e)
{
BO.Messages mail = new BO.Messages();
string body = "Cuerpo Mensaje";
string title = "Titulo";
string script = "alert(\"An email has been sent to the candidate! \");";
mail.refEmail(emailCandi.Text,title,body);
ScriptManager.RegisterStartupScript(this, GetType(),
"ServerControlScript", script, true);
Email_Sent.Visible = true;
changeRefStatus(Int32.Parse(idCand.Text), "1");
}
protected void changeRefStatus(int id, string status)
{
ASF.HC.JobApplication.BO.User u = new ASF.HC.JobApplication.BO.User();
u.saveStatusRef(id,status);
}
public int saveStatusRef(int id, string status)
{
Entity.User u = new Entity.User();
SqlCommand comando = new SqlCommand("dbo.[user_saveStatusRef]", base.Db);
SqlParameter spSearch = new SqlParameter("@id", System.Data.SqlDbType.Int);
SqlParameter spSearch2 = new SqlParameter("@status", System.Data.SqlDbType.VarChar);
spSearch.Value = id;
spSearch.Value = status;
comando.Parameters.Add(spSearch);
comando.Parameters.Add(spSearch2);
return base.ExecuteScalar(comando);
}
存储过程......
ALTER PROCEDURE dbo.user_saveStatusRef
@id int,
@status varchar(5)
AS
UPDATE tbl_user
set statusRef = @status
WHERE id = @id
答案 0 :(得分:4)
可能是拼写错误,但您没有将值分配给spSearch2
spSearch.Value = id;
spSearch.Value = status;