hi everyone,
i need ur help in the following code as i had tried this code many times but doesn't got the desired results. so plz help me out .
SqlCommand cmd1 = new SqlCommand("UPDATE entry SET stock = stock - '"+textBox22.Text+ "'Where name='" + textBox1.Text + "'", conn);
GUI Ado.net connectivity with SQL
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Satyapriya NayakRank #47 · 31.5K reputationPosted Jan 24, 2012, 9:16 PM EST
Try this...
SqlCommand cmd1 = new SqlCommand("UPDATE entry SET stock ='" + textBox22.Text + "' Where name='" + textBox1.Text + "'", conn);
Thanks
Krishna GaradRank #191 · 12.8K reputationPosted Jan 24, 2012, 9:34 PM EST
Create Procedure Sp_UpdateStock
(
@stockval int,
@name Varchar(50)
)
as
Begin
Declare @oldstock int
Set @oldstock=(Select Stock From Entry Where Name=@name)
Begin
Update Entry Set Stock=@oldstock-@stockval Where Name=@name
End
End
And call this procedure from your front end but make sure your old stock value not be null if it is null then set it default to 0.