Friday, September 22, 2006

System.Data.SqlClient.SqlParameterCollection.Add(string, object)' is obsolete: 'Add(String parameterName, Object value) has been deprecated.

For all .NET programmers who are using this

SqlCommand.Parameters.Add("@MyValue","Value");

code in ADO.NET 2.0 will get a deprecation message. Instead of using this code, you need to use the following code

SqlCommand.Parameters.AddWithValue("@MyValue","Value");

this " SqlCommand.Parameters.Add("@MyValue","Value"); " is a ADO.NET 1.1 way of coding, if you are still using this code in ADO.NET 2.0, you will get the following warning message.

" 'System.Data.SqlClient.SqlParameterCollection.Add(string, object)' is obsolete: 'Add(String parameterName, Object value) has been deprecated. Use AddWithValue(String parameterName, Object value). http://go.microsoft.com/fwlink/?linkid=14202' C:\Documents and Settings\501597\My Documents\Visual Studio 2005\WebSites\mytool\MyFirstPage.aspx.cs 149 10 C:\...\doc\ "

This is because of some other API changes in the framework. Checkout the list of obsolete changes in the following links
http://msdn.microsoft.com/netframework/programming/obsoleteapi/ObsByAssembly.aspx
http://www.gotdotnet.com/team/changeinfo/default.aspx

2 comments:

beskito said...

u r genius ... thnx for the help

Unknown said...

Thanks man , saved me a lot of effort

ASP.NET MVC - Sport Facility Booking system

  The project relies on some external service providers. Thus accessing them via their API requires authentication. An API Key need to be su...