Link to home
Start Free TrialLog in
Avatar of webressurs
webressursFlag for Norway

asked on

SQL parameters in ASP.NET, best practise?

Hello,
It is different ways of adding SQL parameters in ASP.NET. I need some info about what I shoul use when adding these parameters. Under is 2 examples that both works fine. The first examples is the fastes to code, but is it as good as the second example? I have also heard aboute using "Parameters.AddWithValue", when is this ment to be used?

--------------------------
Example 1
--------------------------

Cmd.Parameters.Add("@Email", SqlDbType.NVarChar,255).Value = email;

--------------------------
Example 2
--------------------------

SqlParameter Email = new SqlParameter("@Email", SqlDbType.NVarChar,255);
Email.Value = email;
Cmd.Parameters.Add(Email);
ASKER CERTIFIED SOLUTION
Avatar of Anurag Thakur
Anurag Thakur
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of webressurs

ASKER

Thanks for good answers! I lillte this.. did not really get the different between "Cmd.Parameters.Add" and "Cmd.Parameters.AddWithValue"? In this example it seems like it does the same thing:

http://www.aspfree.com/c/a/ASP.NET/Query-Parameters-and-Information-Handling-with-Databases/

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial