my update functions does not work

Hi everyone,
I am having trouble updating information into a form. My saving works fine and retrieving just fine.
I have a store procedure that works this way. If a records exits, update, if it does not exist save a new record.
I tested the store procedure by running it and it works fine if i enter all the variables. If i do not set all variables to Null it wont work. Because of this, on the website i added the following code.
            if (!IsEmpty(TaskAss1.Text))
                cmd.Parameters.Add(new SqlParameter("@TaskAss1",  TaskAss1.Text.Trim()));
            else
                cmd.Parameters.Add(new SqlParameter("@TaskAss1", DBNull.Value));

basically to enter null if there is no value on the textbox. Still does not update. I don't know what else do to.
I do not receive any error on the website when i try to update, but i see that the data has not been update.

any suggestion , will be very appreciated
shpresaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

shpresaAuthor Commented:
I also just tried this for all my fields
cmd.Parameters.Add(new SqlParameter("@TaskAss1", DBNull.Value));

updating basing to null values and it worked. SO to me sounds like a null problem. Looks like i m not saving correctly on the webpage.

Any suggestion?
0
Brendt HessSenior DBACommented:
If your parameters on the stored procedure can be NULL, it is possible to change the parameters to an optional parameter. So, if your procedure looked like:

CREATE PROCEDURE MyUpdate 
    @param1 varchar(20), 
    @param2 int, 
    @ param3 datetime
AS
....

Open in new window

... and the last two parameters were optional, you could rewrite the definition as :

CREATE PROCEDURE MyUpdate 
    @param1 varchar(20), 
    @param2 int = NULL, 
    @ param3 datetime = NULL
AS
....

Open in new window


Now, if you don't pass in an optional parameter, the parameter will be set to NULL by default, instead of generating an error, so this call is legal:

EXEC MyUpdate @param1='bob'

Open in new window

as is this:

EXEC MyUpdate @param1='bob', @param3='20150101'

Open in new window

0
shpresaAuthor Commented:
I tried placing the variable = null and it is still the same, does not update.
it seems to me that when i check for emty
         if (!IsEmpty(Challenges1.Text))
                cmd.Parameters.Add(new SqlParameter("@Challenges1", Challenges1.Text.Trim()));
            else
                cmd.Parameters.Add(new SqlParameter("@Challenges1", DBNull.Value));
 
it does not pass at all, it does not read it. seems like there is something wrong weith the above lines of code.
Anytime, i place a value
  cmd.Parameters.Add(new SqlParameter("@Challenges1", "test"));
it works.
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

sammySeltzerCommented:
It will be nice to show more code but try this:

if (Challenges1.Text==null) {
    cmd.Parameters("@Challenges1").Value = DBNull.Value;
} else {
    cmd.Parameters("@Challenges1").Value = Challenges1.Text;
}

Open in new window


My laptop was acting up I didn't finish my thoughts.

Also, make sure that your asp.net code uses same parameter name as your stored proc.

Finally, you probably need to use Try..Catch to help with the actual problem.
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
Can you post your SP definition?
0
shpresaAuthor Commented:
Hi Everyone,

It seemed that i had to clear up my cashe to have the update function to work. Everything else was fine.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shpresaAuthor Commented:
that was the solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.