Reputation: 43
I have a field named customerName
in database and might many time this field was Initialized I want save my Previous values and append new value at end of field as string.
My proc:
CREATE PROC sp_GpInsert
@CName nvarchar(450),
@CEmail VARCHAR(250),
@GName NVARCHAR(70)
AS
BEGIN
Update TBLGroupCustomers
SET
CustomersName=@CName,
CustomerEmail=@CEmail
WHERE GName=@Gname
END
My code:
SqlCommand cmd1 = new SqlCommand("sp_GpInsert", conn);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.Add(new SqlParameter("@CName", txtCName.Value));
cmd1.Parameters.Add(new SqlParameter("@CEmail", txtemail.Value));
cmd1.Parameters.Add(new SqlParameter("@GName", YrStr));
cmd1.ExecuteNonQuery();
This code cannot save the Previous value.
Upvotes: 0
Views: 76
Reputation: 3352
you have to do like that
Update TBLGroupCustomers
SET
CustomersName= ISNULL(CustomersName ,'')+ @CName,
CustomerEmail=@CEmail
WHERE GName=@Gname
Upvotes: 1