parameters.add is obsolete in vb.net 2.0?

dalem

Member
Joined
Apr 11, 2005
Messages
17
Programming Experience
10+
hope this is the right place to post this question

i recently converted a 2003 vb.net project to 2005--cleaned up the errors and it runs ok but it gives me warnings about using public function "parameters.add() for inserting records into sql table--says that is now obsolete and has been replaced by "parameters.addvalue"

the code in 2005 runs with either but the 2003 code will not accept the "addvalue" function--

since i continue to do most of my coding in 2003 but want to make sure that there is minimal work to do in those cases where i have to upgrade any particular project, i'm interested in finding out if there is any function that i can use in 2003 that won't give the "warnings" in 2005 or am i just stuck with either ignoring the warnings or doing a global search and replace if i do convert it to 2005.

the microsoft site mentioned by the vs 2005 warning statement was of no help.

hope this makes sense--thanks for any help you can give. my experience in 2005 is minimal except that its lumbering makes me appreciate staying with 2003 as long as i have!

dale
 
Only one of the 6 Add overloads is obsolete, and has been replaced by the more logically named AddWithValue method. It makes sense since adding a parameter to the command and setting a value for the parameter is two distinct operations. (better OOP in practice)
You still can do both in one line of code like:
command.parameters.add(new sqlparameter("name", "value")) 'a different Add overload, one of the sqlparameter constructors is used to also set its value.
command.parameters.add("name", type).Value = "value" 'this overload of Add returns a sqlparameter whose Value property is set after the Add operation is done.
etc...
 
2005 lumbering? How?


When a method becomes obsolete, it's for good reason usually. Often, there was a way to do X in 2003 that was deemed wrong in 2005 and was obsoleted. Its not always the case that the "right" way existed in 2003, so yep youre going to have to find/replace


Of particular note though, is that parameters.Add doesnt/SHOULDNT get used all that much in 2005, because the IDE includes a very good code generator that writes most of that crap, tediuos, boring data access code for you. You provide the SQL, it looks at the table, works out the parameters, their types, writes all the add code, and wraps it up in a nice function for you to call.. It even goes as far as to make versions of the function that acccept data rows; you load the rows with the values, and send them in and it digs all the values out, assigns them to the proper params and runs the statement

The end result is that you can call:



Update(myNewRow)


Where myNewRow is loaded wiht the values you set (or got the user to set through databinding) - the update command works out whether this row is New, Changed or Deleted, and calls teh relevant INSERT UPDATE or DELETE SQL (which it worked out automatically at design time)


I think you should open 2005, and spend some time working throught the tuts in the DW2 link in my sig; you'll get to appreciate what an awkward pig 2003 really is for data access!
 
Back
Top