我在这里遇到了麻烦。我在 windows_loaded 事件中添加了它。代码在这里:
con.Open();
int i = 0, j = 0;
string[] productCode = null;
string[] productName = null;
int[] quantity =null;
float[] totalPrice = null;
float[] totalTax = null;
int orderID = 0;
SqlCeCommand com5 = new SqlCeCommand("SELECT MAX(OrderID) AS Expr1 FROM Order_Details", con);
orderID = (int)com5.ExecuteScalar();
SqlCeCommand com1 = new SqlCeCommand("SELECT ProductCode, Quantity FROM Order_Products WHERE OrderID = ('"+ orderID.ToString() +"')", con);
SqlCeDataReader dr1 = com1.ExecuteReader();
while (dr1.Read())
{
productCode[i] = (string)dr1[0]; // Exception is here
quantity[i] = (int)dr1[1];
SqlCeCommand com3 = new SqlCeCommand("SELECT ProductName FROM Products_Master WHERE ProductCode = '" + productCode[i] + "'", con);
productName[i] = (string)com3.ExecuteScalar();
i++;
}
SqlCeCommand com2 = new SqlCeCommand("SELECT TotalPrice, TotalTax FROM Order_Details WHERE OrderID = (SELECT MAX(OrderID) AS Expr1 FROM Order_Details)", con);
SqlCeDataReader dr2 = com1.ExecuteReader();
while (dr2.Read())
{
totalPrice[j] = (float)dr2[0];
totalTax[j] = (float)dr2[1];
j++;
}
for (int k = 1; k <= i; k++)
{
List<Product> Products = new List<Product>();
Product p = new Product
{
ID = k,
ProductName = productName[k],
Quantity = quantity[k],
Tax = totalTax[k],
Total = totalPrice[k]
};
dgrdInvoice.Items.Add(p); // add a row
}
con.Close();
任何人都可以为我找到解决此问题的方法吗?我正在尝试将两个数据库中的值添加到单个 DataGrid。
编辑:
实际上在 SQL 查询中有一些东西:
数据类型对布尔表达式无效。[数据类型(如果已知)= int ,数据类型(如果未知)= nvarchar]。