0

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 次相同的错误任何人都可以给我任何建议

4

2 回答 2

3

不匹配的右括号:

[total]=@val1)
            ^^^
于 2013-04-21T13:10:24.490 回答
0

从第 4 行删除额外内容)可能会有所帮助。所以应该是这样的:

SqlCeCommand cmmmmd = 
    new SqlCeCommand("update [Dept_Sales] SET [total]=@val1 
                      where [department]=@val2", conn);
于 2013-04-21T13:10:11.930 回答