|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
parameters.Add("@f"...) vs parameters.Add(New SqlParameter("@f"da.InsertCommand.Parameters.Add(New SqlParameter("@f", SqlDBtype.Varchar, 10,
"fld1")) da.Fill(ds, "tbl1") The statements below will insert a row into "tbl1" just as well as the statement above da.InsertCommand.Parameters.Add("@f", SqlDBtype.Varchar, 10, "fld1") da.Fill(ds, "tbl1") Is there any difference if I use ..Add(New SqlParameter(...) or omit --New SqlParameter--? I want to follow the proper convention. Any suggestions appreciated. Thanks, Rich In article <2695FF6B-0CEC-4966-8D6F-65F0B4B37***@microsoft.com>,
R***@discussions.microsoft.com says... > da.InsertCommand.Parameters.Add(New SqlParameter("@f", SqlDBtype.Varchar, 10, They do the exact same thing. In fact, if you look inside the framework > "fld1")) > da.Fill(ds, "tbl1") > > The statements below will insert a row into "tbl1" just as well as the > statement above > > da.InsertCommand.Parameters.Add("@f", SqlDBtype.Varchar, 10, "fld1") > da.Fill(ds, "tbl1") > > Is there any difference if I use ..Add(New SqlParameter(...) or omit --New > SqlParameter--? I want to follow the proper convention. Any suggestions > appreciated. for the SqlParameterCollection.Add method using Reflector, you'll see that the second method you listed actually runs the same code as the first method listed. :) Very interesting. So it looks like I could reduce my code by eliminating
New SqlCommand and the 2 extra parens. But if I do this instead Dim prm1, prm2, prm3, prm4() as sqlparameter .... prm4 = New Sqlparameter(){prm1, prm2, prm3} for each prm As SqlParameter) in prm4 da.InsertCommand.Parameters.Add(prm) Next Hmmm, I think I could still get away without using New SqlParameter with prm1, prm2, prm3. Interesting. Show quote "Patrick Steele" wrote: > In article <2695FF6B-0CEC-4966-8D6F-65F0B4B37***@microsoft.com>, > R***@discussions.microsoft.com says... > > da.InsertCommand.Parameters.Add(New SqlParameter("@f", SqlDBtype.Varchar, 10, > > "fld1")) > > da.Fill(ds, "tbl1") > > > > The statements below will insert a row into "tbl1" just as well as the > > statement above > > > > da.InsertCommand.Parameters.Add("@f", SqlDBtype.Varchar, 10, "fld1") > > da.Fill(ds, "tbl1") > > > > Is there any difference if I use ..Add(New SqlParameter(...) or omit --New > > SqlParameter--? I want to follow the proper convention. Any suggestions > > appreciated. > > They do the exact same thing. In fact, if you look inside the framework > for the SqlParameterCollection.Add method using Reflector, you'll see > that the second method you listed actually runs the same code as the > first method listed. :) > > -- > Patrick Steele > http://weblogs.asp.net/psteele > |
|||||||||||||||||||||||