Doubt1 - What is the difference between these 2 statements in ado.net?

Posted by Arjunan_Csharp under C# on 1/18/2013 | Points: 10 | Views : 1392 | Status : [Member] | Replies : 2
Please Clarify my doubts here.What is the mojor difference here.
1) command.Parameters.AddWithValue("@Age", ageTextBox.Text);
2)command.Parameters.Add("@Age",SqlDbType.Int,2).Value=ageTextBox.Text

This is what i know in terms of difference.Please correct me if i do any mistakes.

Statement1 - AddWithValue always sends nvarchar value to the database.my doubts is - if i created a column[ say Age Field] in database where its datatype in integer.so i use addwith value,it will send a nvarchar to the database so Datatype mismatch here.Does it throw any error ?




Responses

Posted by: Saratvaddilli on: 1/19/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi arjunan,

As per me it will not throw any exception or error because it will do implicit casting/conversion in the DBMS,


Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Arjunan_Csharp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kundnani.Rt on: 1/19/2013 [Member] Starter | Points: 25

Up
0
Down
I think first one is correct.

Second one is C# Syantax Error

Arjunan_Csharp, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response