Asp.Net / SQL2005 Stored Procedure Update Problem
-
Hi, Im using a stroed procedure to update records in a SQL2005 DB. To send info to the procedure i run something similar to this:
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@email", tbxUsername.Text);
cmd.Parameters.AddWithValue("@password", tbxPass.Text);
cmd.ExecuteNonQuery();Under certain circumstance i wont want to update the @password field. Is this possible, if so how? Or do i need to use a seperate stored procedure which doesnt mention the field(s) which shouldn't be updated? Thanks.
-
Hi, Im using a stroed procedure to update records in a SQL2005 DB. To send info to the procedure i run something similar to this:
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@email", tbxUsername.Text);
cmd.Parameters.AddWithValue("@password", tbxPass.Text);
cmd.ExecuteNonQuery();Under certain circumstance i wont want to update the @password field. Is this possible, if so how? Or do i need to use a seperate stored procedure which doesnt mention the field(s) which shouldn't be updated? Thanks.
The logic is entirely up to you, since I don't know the detail I can't guide you on what is the best course of action. I would say that if the code will do different things then it should be in a different sproc. Does the current sproc do more than update the password? If so what? And what circumstances don't you want to sproc to update the password. And this question belongs in the database forum.
Man who stand on hill with mouth open wait long time for roast duck to drop in
-
Hi, Im using a stroed procedure to update records in a SQL2005 DB. To send info to the procedure i run something similar to this:
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@email", tbxUsername.Text);
cmd.Parameters.AddWithValue("@password", tbxPass.Text);
cmd.ExecuteNonQuery();Under certain circumstance i wont want to update the @password field. Is this possible, if so how? Or do i need to use a seperate stored procedure which doesnt mention the field(s) which shouldn't be updated? Thanks.
Hey... you are not running a query. Just check the value of password, send DbNull.Value from here and check in the stored Proc :
If @password IS NULL
BEGIN
-- Update only the UserName
END
ELSE
BEGIN
-- UPDATE both username and password.
END:rose::rose:
Abhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
Create .NET Templates