开发者

Error in asp.net scalar variable

If you please help me out I have an error and I am trying to understand what the error is all about so I can fix it since I am a beginner.

My error is:

Must declare the scalar variable "@Details"

And my function goes like this:

public static void CreateReview(string paperId, string grate, string criteriaId, string Details)
{
    var sqlCon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

             // GET CONFERENCE ROLE ID
             SqlCommand cmd = new SqlCommand();
             cmd.Connection = sqlCon;
             cmd.CommandText = "select Conference_Role_ID from AuthorPaper where Paper_ID = @PaperId";
          开发者_运维知识库   cmd.Parameters.AddWithValue("@PaperId", paperId);
             cmd.Connection.Open();
             string ConferenceRoleId = cmd.ExecuteScalar().ToString();
             cmd.Connection.Close();
             cmd.Dispose();

             string query2 = @"insert into ReviewPaper(Overall_Rating,Paper_id,Conference_role_id,Details)
             values(0,@paperId,@ConferenceRoleId,@Details); select
 SCOPE_IDENTITY() as RPID";

             cmd = new SqlCommand(query2, sqlCon);
                 cmd.Parameters.AddWithValue("@paperId",
 paperId);
                 cmd.Parameters.AddWithValue("@ConferenceRoleId",
 ConferenceRoleId);

             string ReviewPaperId;

                 try
                 {
                     cmd.Connection.Open();
                     ReviewPaperId = cmd.ExecuteScalar().ToString();
                     cmd.Connection.Close();
                 }
                 catch (Exception ee) { throw ee; }
                 finally { cmd.Dispose(); } }

If i delete details my function works perfectly. Thanking you in advance.


You need a line:

cmd.Parameters.AddWithValue("@Details", Details);

You are executing statement that takes 3 parameters but you are supplying only two.


You need to add a new parameter to your SqlCommand that represents @Details

cmd = new SqlCommand(query2, sqlCon);
cmd.Parameters.AddWithValue("@paperId",paperId);
cmd.Parameters.AddWithValue("@ConferenceRoleId", ConferenceRoleId);

// Add the details parameter
cmd.Parameters.AddWithValue("@Details", Details);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜