请把我推出去,我有个错误
错误:
必须声明标量变量“@Criteria”。
因为我没有太多的经验,我找不出问题,谢谢
密码:
public static void CreateReveiw(string paperId, string Criteria_Id, string Grate)
{
var sqlCon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlCon;
cmd.CommandText = "select Review_paper_ID from ReviewPaper where Paper_ID= @PaperId";
cmd.Parameters.AddWithValue("@PaperId", paperId);
cmd.Connection.Open();
string Review_paper_ID = cmd.ExecuteScalar().ToString();
cmd.Connection.Close();
cmd.Dispose();
string query2 = @"insert into ReviewPaperCriteria(Review_paper_ID,Criteria_ID,Grate)
values(@Review_paper_ID,@Criteria,@Grate);select SCOPE_IDENTITY() as RPID";
cmd = new SqlCommand(query2, sqlCon);
cmd.Parameters.AddWithValue("@Review_paper_ID", Review_paper_ID);
cmd.Parameters.AddWithValue("@Criteria_ID", Criteria_Id);
cmd.Parameters.AddWithValue("@Grate", Grate);
string ReviewPaperId;
try
{
cmd.Connection.Open();
ReviewPaperId = cmd.ExecuteScalar().ToString();
cmd.Connection.Close();
}
catch (Exception ee) { throw ee; }
finally { cmd.Dispose(); }
}
3条答案
按热度按时间ppcbkaq51#
变更
至
或者更改查询字符串(query 2)以匹配所使用的参数名称(@Criteria_ID)。
im9ewurl2#
您的参数是
@Criteria_ID
,但您在SQL中引用了@Criteria
。您需要在其中一个位置更改该参数以保持一致。b4qexyjb3#
您正在声明变量
@Criteria
,但试图使用@Criteria_ID
设置其值。变更
结束日期