C#修改数据库调用updata指令时出现,'=' 附近有语法错误。什么原因导致这个问题,求高手解决
publicvoidUpdateFinalScore(stringSname,stringC_Sname){//修改FinalScore表的成绩SqlConnection...
public void UpdateFinalScore(string Sname, string C_Sname) {//修改FinalScore表的成绩
SqlConnection conn = new SqlConnection(Properties.Settings.Default.GradeManagementSystemConnectionString);
SqlCommand comm = new SqlCommand("update FinalScore set " + C_Sname + " = '0' where Sname='" + Sname + "' ", conn);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
} 展开
SqlConnection conn = new SqlConnection(Properties.Settings.Default.GradeManagementSystemConnectionString);
SqlCommand comm = new SqlCommand("update FinalScore set " + C_Sname + " = '0' where Sname='" + Sname + "' ", conn);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
} 展开
7个回答
展开全部
sql语句有错
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
// 查询语句
var sql = string.Format("UPDATE FinalScore SET [{0}] = '{1}' WHERE Sname = '{2}'", C_Sname, 0, Sname);
Console.WriteLine(sql); // 在输出窗口打印查询语句
try
{
var cn = new SqlConnection(...);
var cmd = new SqlCommand(sql, cn);
cmd.Connection.Open();
var result = cmd.ExecuteNonQuery();
cn.Close();
}
catch(System.Exception ex)
{
Console.WriteLine(ex.ToString()); // 显示异常的完整信息
}
var sql = string.Format("UPDATE FinalScore SET [{0}] = '{1}' WHERE Sname = '{2}'", C_Sname, 0, Sname);
Console.WriteLine(sql); // 在输出窗口打印查询语句
try
{
var cn = new SqlConnection(...);
var cmd = new SqlCommand(sql, cn);
cmd.Connection.Open();
var result = cmd.ExecuteNonQuery();
cn.Close();
}
catch(System.Exception ex)
{
Console.WriteLine(ex.ToString()); // 显示异常的完整信息
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询