开发者

Question in error in asp.net c#

i have a question if you please help me i have an error

Must declare the scalar variable "@Deitails".

and i can not find out whats the problem since i am not aware what Scalar is about

 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,Deita开发者_如何学Goils)

                              values(0,@paperId,@ConferenceRoleId,@Deitails);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(); }

thanks


You have a SQL query with a parameter named Details, but you forgot to add the parameter.


You have a line of code which says

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

You provide the parameters @paperId, @ConferenceRoleId and @Deitails for the values for the insert statement. Later you specify the value for the first two parameters, but not @Deitails:

cmd.Parameters.AddWithValue("@paperId", paperId);
cmd.Parameters.AddWithValue("@ConferenceRoleId", ConferenceRoleId);

You need to add a similar line to add the value for @Deitails so that SQL server knows what to do with it. The error you are getting is coming from SQL server because by not adding a value for @Deitails in your C# code, it is not being declared for you in the SQL code which is sent to the server.

To answer your other question, 'Scalar' in this case means that the variable @Deitails represents a single value.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜