c#我想更新sql不同的值但错误帮助我

时间:2016-07-10 12:54:00

标签: c# sql-server

StockCalulate Aleart

图片1:

enter image description here

图片2:

enter image description here

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);
}

1 个答案:

答案 0 :(得分:-1)

尝试以下

            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);