C#错误解析查询令牌行号1
cmmd.CommandText = "Select total from Dept_Sales where department ='" + department + "'";
var dtotal = cmmd.ExecuteScalar().ToString();
var nntotal = dtotal + price;
SqlCeCommand cmmmmd = new SqlCeCommand("update [Dept_Sales] SET [total]=@val1) where [department]=@val2", conn);
{
cmmmmd.Parameters.AddWithValue("@val1", nntotal);
cmmmmd.Parameters.AddWithValue("@val2", department);
cmmmmd.CommandType = System.Data.CommandType.Text;
cmmmmd.ExecuteNonQuery() }
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
also dtotal =3.51
and price = 3.51
nntotal = 7.02
我认为在我的查询中可能有一个问题我已经改变了15次相同的错误,任何人都可以给我任何建议
答案 0 :(得分:3)
不匹配的右括号:
[total]=@val1)
^^^
答案 1 :(得分:0)
从第4行删除外部)
可能会有所帮助。所以它应该是这样的:
SqlCeCommand cmmmmd =
new SqlCeCommand("update [Dept_Sales] SET [total]=@val1
where [department]=@val2", conn);