开发者

scalar variable error

if you please heap me out i have an error

error:

Must declare the scalar variable "@Criteria".

since i don't have a lot of experience i can not find the problem thanks

code:

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.Ope开发者_JS百科n();
    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(); }



    }


Change

cmd.Parameters.AddWithValue("@Criteria_ID", Criteria_Id);

to

cmd.Parameters.AddWithValue("@Criteria", Criteria_Id);

or change the query string (query2) to match the parameter name (@Criteria_ID) that's used.


Your parameter is @Criteria_ID but you reference @Criteria in the SQL. You need to change it in one of the locations to be consistent.

string query2 = @"insert into ReviewPaperCriteria(Review_paper_ID,Criteria_ID,Grate) 
                 values(@Review_paper_ID,@Criteria,@Grate);select SCOPE_IDENTITY() as RPID";
                                         ^^^^^^^^^    
...

cmd.Parameters.AddWithValue("@Criteria_ID", Criteria_Id);
                             ^^^^^^^^^^^^


You're declaring the variable @Criteria but attempting to set its value using @Criteria_ID.

Change

 cmd.Parameters.AddWithValue("@Criteria_ID", Criteria_Id);

To

 cmd.Parameters.AddWithValue("@Criteria", Criteria_Id);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜