当我在表格中插入数据时,它会给我错误
public int SolveSection(string sectionName, string userid, string examId, string TotalSolveQuestion, string time)
{
SqlCeCommand cmd = new SqlCeCommand();
int a = 0;
Random rnd = new Random();
_connection.Open();
cmd.Parameters.Add(new SqlCeParameter("@User_id", userid));
cmd.Parameters.Add(new SqlCeParameter("@Exame_id", examId));
cmd.Parameters.Add(new SqlCeParameter("@Interactive usage of English_Solve_Total_qouation", TotalSolveQuestion));
cmd.Parameters.Add(new SqlCeParameter("@Interactive usage of EnglishT", time));
cmd.Parameters.Add(new SqlCeParameter("@Interactive usage of English", sectionName));
cmd.Connection = _connection;
//cmd.CommandText = "Insert into [Personal_information_ofcandidat](User_id,Name,MName,LName,Exam_date,Exam_id,College_Name,Email_id,Phone_no) values('" + userid + "','" + uname + "','" + muname + "','" + luname + "','" + DateTime.Now + "','" + examid + "','" + collegname + "','" + email + "','" + mobile + "')";
cmd.CommandText = "Insert into [Solve_Question](user_id,Exame_id,Interactive usage of English_Solve_Total_qouation,Interactive usage of EnglishT,Interactive usage of English)" + "values(@User_id,@Exame_id,@Interactive usage of English_Solve_Total_qouation,@Interactive usage of EnglishT,@Interactive usage of English)";
cmd.CommandType = CommandType.Text;
try
{
a = cmd.ExecuteNonQuery();
if (a > 0)
{
}
else { userid = ""; }
_connection.Dispose();
}
catch (Exception ee) { }
return a;
}
它给出了一条错误消息:
解析查询时出错。 [令牌行号= 1,令牌行偏移= 59,令牌错误=使用] 在线ExecuteNonQuery()行。哪里我错了。
答案 0 :(得分:3)
从列名称和参数名称中删除空格,如果希望列名称包含空格,则将它们放入[column Name]
。
cmd.Parameters.Add(new SqlCeParameter("@User_id", userid));
cmd.Parameters.Add(new SqlCeParameter("@Exame_id", examId));
cmd.Parameters.Add(new SqlCeParameter("@Interactive_usage_of_English_Solve_Total_qouation", TotalSolveQuestion));
cmd.Parameters.Add(new SqlCeParameter("@Interactive_usage_of_EnglishT", time));
cmd.Parameters.Add(new SqlCeParameter("@Interactive_usage_of_English", sectionName));
cmd.Connection = _connection;
//cmd.CommandText = "Insert into [Personal_information_ofcandidat](User_id,Name,MName,LName,Exam_date,Exam_id,College_Name,Email_id,Phone_no) values('" + userid + "','" + uname + "','" + muname + "','" + luname + "','" + DateTime.Now + "','" + examid + "','" + collegname + "','" + email + "','" + mobile + "')";
cmd.CommandText = "Insert into [Solve_Question] (user_id,Exame_id,[Interactive usage of English_Solve_Total_qouation],[Interactive usage of EnglishT],[Interactive usage of English])" + "values (@User_id,@Exame_id,@Interactive_usage_of_English_Solve_Total_qouation, @Interactive_usage_of_EnglishT,@Interactive_usage_of_English)";