-2
StockCalulate AleartC#我想更新SQL不同的值,但錯誤幫助我
圖1:
圖2:
CODE:
try {
con = new SqlConnection(cs.DBConn);
con.Open();
string cb = "Update OrderDetailNum set ImportPrice = (@d1 /100) * (select StockCalulate=((StockCalulate/Sum(StockCalulate))*100) from OrderDetailNum Where StockID='" + lblStockID.Text + "' AND Orderid='" + comboOrder.Text + "' group by StockCalulate) Where StockID='" + lblStockID.Text + "' AND Orderid='" + comboOrder.Text + "'";
cmd = new SqlCommand(cb);
cmd.Connection = con;
cmd.Parameters.AddWithValue("@d1", Convert.ToDecimal(lblPr.Text.ToString()));
cmd.ExecuteReader();
con.Close();
MessageBox.Show("Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
dataGridView1.DataSource = GetData();
ClearAllText(this);
} catch (Exception ex) {
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
你似乎更多的是SQL問題,我會編輯的問題,並把只注重查詢。 –
[SQL Server子查詢的可能重複項返回多個值。當子查詢遵循(字符)或子查詢用作表達式時,這是不允許的(http://stackoverflow.com/questions/22909737/sql-server-subquery-returned-more-than-1-value-這是不允許的 - 當 - s) –
[*** SQL注入警報***](http://msdn.microsoft.com/en-us/library/ms161953%28v=sql.105 %29.aspx) - 您應該**不**將您的SQL語句連接在一起 - 使用**參數化查詢**代替以避免SQL注入 –