异常详细信息: System.Data.SqlClient.SqlException: 必须声明标量变量 "@UserID"。
protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
{
string PaperName = Xpaperid.Text;
Scores scores = new Scores();
scores.UserID = Request["UserID"].ToString();
scores.Score = Convert.ToInt32(sumScore.Text);
scores.ExamTime = Convert.ToDateTime(lblExamtime.Text);
scores.JudgeTime = DateTime.Now; string userId = Request["UserID"].ToString();
int paperId = int.Parse(Request["PaperID"]);
if (UserManager.InsertScores(scores, PaperName, userId, paperId))
{
lblMessage.Text = "插入成功!";
}
else
{
lblMessage.Text = "插入失败!";
}
}
我点保存按钮的时候就出现这个问题,不能把数据存入数据库,请高手帮帮忙,谢谢!!最好具体点,我初学。。
protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
{
string PaperName = Xpaperid.Text;
Scores scores = new Scores();
scores.UserID = Request["UserID"].ToString();
scores.Score = Convert.ToInt32(sumScore.Text);
scores.ExamTime = Convert.ToDateTime(lblExamtime.Text);
scores.JudgeTime = DateTime.Now; string userId = Request["UserID"].ToString();
int paperId = int.Parse(Request["PaperID"]);
if (UserManager.InsertScores(scores, PaperName, userId, paperId))
{
lblMessage.Text = "插入成功!";
}
else
{
lblMessage.Text = "插入失败!";
}
}
我点保存按钮的时候就出现这个问题,不能把数据存入数据库,请高手帮帮忙,谢谢!!最好具体点,我初学。。
public static bool InsertScore(Scores score, string PaperName, string userId, int paperId)
{
if (SeclctCheck(userId, paperId))
{
using (SqlConnection con = DBHelp.GetConnection())
{
string sql = @"insert into Score
(UserID,PaperID,Score,ExamTime,JudgeTime)
select
@UserID,
PaperID,
@Score,
@ExamTime,
@JudgeTime
from
Paper
where
PaperName = '" + PaperName + "'";
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@UserId",score.UserID),
new SqlParameter("@PaperID",score.PaperID),
new SqlParameter("@Score",score.Score),
new SqlParameter("@ExamTime",score.ExamTime),
new SqlParameter("@JudgeTime",score.JudgeTime)
}; int i = DBHelp.ExecuteCommand(sql, para);
if (i > 0)
{
return true;
}
else
{
return false;
}
} }
return false; }
@UserID,
PaperID,
@Score,
@ExamTime,
@JudgeTime
from
Paper
where
PaperName = '" + PaperName + "'";
这里的"@UserID"和下面的"UserId"不一致
new SqlParameter("@UserId",score.UserID),另外,你的“PaperID”前缺少“@”符号,
@UserID,
PaperID, @Score,
@ExamTime,
@JudgeTime写程序一定要仔细哦!
@UserID,
@PaperID,
@Score,
@ExamTime,
@JudgeTime
new SqlParameter("@UserID",score.UserID),