Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# asp.net标量变量中存在错误_C#_Asp.net_Sql - Fatal编程技术网

C# asp.net标量变量中存在错误

C# asp.net标量变量中存在错误,c#,asp.net,sql,C#,Asp.net,Sql,如果你能帮助我,我有一个错误,我正试图了解错误是怎么回事,这样我就可以修复它,因为我是一个初学者 我的错误是: Must declare the scalar variable "@Details" 我的函数是这样的: public static void CreateReview(string paperId, string grate, string criteriaId, string Details) { var sqlCon = new SqlConnection(Syste

如果你能帮助我,我有一个错误,我正试图了解错误是怎么回事,这样我就可以修复它,因为我是一个初学者

我的错误是:

Must declare the scalar variable "@Details"
我的函数是这样的:

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(); } }
如果我删除了详细信息,我的功能将完美运行。提前感谢您。

您需要一条线路:

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

您正在执行接受3个参数的语句,但只提供了两个参数。

您需要向SqlCommand添加一个表示@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);