0

我收到错误,这里有什么问题?

SqlCeCommand com5 = new SqlCeCommand("SELECT MAX(OrderID) AS Expr1 FROM Order_Details)", con);
SqlCeDataReader dr5 = com5.ExecuteReader(); // Catches Ex here
while (dr5.Read())
{
     orderID = Convert.ToInt32(dr[0]);
}

我正在SQLCe使用VS2012, WPF, C#

例外是

$exception {"解析查询时出错。[标记行号 = 1,标记行偏移量 = 62,错误标记 = )]"} System.Exception {System.Data.SqlServerCe.SqlCeException}`

查询正确,但这些查询没有更新我的数据库,你能查一下吗?

SqlCeCommand com3 = new SqlCeCommand("INSERT INTO Order_Details(Discount, TotalPrice, TotalTax) VALUES(@Discount, @TotalPrice, @TotalTax)", con);
                com3.Parameters.AddWithValue("@Discount", discount);
                com3.Parameters.AddWithValue("@TotalPrice", gTotal);
                com3.Parameters.AddWithValue("@TotalTax", totalIndividualTax);
4

3 回答 3

2

去掉)最后的

SELECT MAX(OrderID) AS Expr1 FROM Order_Details)
                                               ^--here
于 2013-10-31T07:15:31.813 回答
1

)零件后有一个额外的支架FROM Order_Details。只需将其删除。

将其更改为;

SqlCeCommand com5 = new SqlCeCommand("SELECT MAX(OrderID) AS Expr1 FROM Order_Details", con);
SqlCeDataReader dr5 = com5.ExecuteReader(); // Catches Ex here
while (dr5.Read())
{
     orderID = Convert.ToInt32(dr[0]);
}

顺便说一句,我不明白你为什么在ExecuteReader这里使用。由于您只返回一行一列,因此使用ExecuteScalar会更好。

例如;

SqlCeCommand com5 = new SqlCeCommand("SELECT MAX(OrderID) AS Expr1 FROM Order_Details", con);
orderID = (int)com5.ExecuteScalar(); 
于 2013-10-31T07:16:31.213 回答
1

此处删除括号:

SqlCeCommand com5 = new SqlCeCommand("SELECT... Order_Details)", con);
                                                             ^
于 2013-10-31T07:18:17.410 回答