Reputation: 11393
I want to know what's the difference between:
DBCmd.Parameters.Add("user_name", IfxType.VarChar);
DBCmd.Parameters["user_name"].Value = p_u;
and
DBCmd.Parameters.Add("user_name", p_u);
What's the best practice here, which one is safer, and does one perform better than the other?
Upvotes: 3
Views: 236
Reputation: 51494
Notwithstanding Marc's answer, Parameters.Add
to add a value is deprecated - It was replaced with AddWithValue
Upvotes: 1
Reputation: 1062820
In the example shown, the primary difference is that it knows the type to use is explicitly IfxType.VarChar
- this might be important, depending on the exact situation, and whether IFX defaults strings as Char
, VarChar
, or LongVarChar
. I honestly don't know which of those it would select by default.
Being explicit is usually a good idea, but there is no need to re-fetch via the indexer, since the new parameter is returned from Add
; I would probably suggest:
DBCmd.Parameters.Add("user_name", IfxType.VarChar).Value = p_u;
or maybe:
DBCmd.Parameters.Add("user_name", IfxType.VarChar, 20).Value = p_u;
where 20
is the size of the parameter.
Upvotes: 5