Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
SqlCommand UpdateCommand = new SqlCommand("Update Stock Set ConfigID = @ConfigID , Quantity = @Quantity ,TotalPrice =@TotalPrice, StockDate =@StockDate ,Where StockID='" + txtStockID.Text + "'");
                UpdateCommand.Connection = con;
                UpdateCommand.Parameters.Add("@ConfigID",SqlDbType.Int).Value= txtConfigID.Text;
                UpdateCommand.Parameters.Add("@Quantity", SqlDbType.Int).Value = txtQty.Text;
                UpdateCommand.Parameters.Add("@TotalPrice", SqlDbType.Int).Value = txtTotalPrice.Text;
                UpdateCommand.Parameters.Add("@StockDate", SqlDbType.NVarChar, 50).Value = dtpStockDate.Value;
                con.Open();
                UpdateCommand.ExecuteNonQuery();
Con.Close();
Posted

Remoce "," from query and try this.. :)

C#
SqlCommand UpdateCommand = new SqlCommand("Update Stock Set ConfigID = @ConfigID , Quantity = @Quantity ,TotalPrice =@TotalPrice, StockDate =@StockDate Where StockID='" + txtStockID.Text + "'");
 
Share this answer
 
v2
And to add to Nirav's answer, since you already use SqlParameters for the values, you should also use SqlParameter for the WHERE clause instead of concatenating txtStockID.Text directly to the string.

Direct concatenation leaves you open to SQL injections etc as you're already probably aware of :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900