[英]c# I want update sql different Value but Error Help me
股票計算警報
圖片1:
圖2:
代碼:
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);
}
嘗試以下
string cb = string.Format("Update OrderDetailNum set ImportPrice = (@d1 /100) * (select StockCalulate=((StockCalulate/Sum(StockCalulate))*100))" +
" from OrderDetailNum" +
" Where StockID='{0}' AND Orderid='{1}'",
lblStockID.Text, comboOrder.Text);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.