重构-只需编写SqlParameterCollection.Add方法已过时

重构-只需编写SqlParameterCollection.Add方法已过时,sql,c#-4.0,Sql,C# 4.0,我目前正在使用工具Just code重构代码,该工具显示以下警告之一: System.Data.SqlClient.SqlParameterCollection.Addstring对象已过时 我还从MSDN中发现: SqlParameterCollection。添加方法字符串,对象 注意:此API现在已过时 我想知道是否应该重构此代码: SqlCommand cmdGetIds= oConn.CreateCommand(); cmdGetIds.CommandType = CommandType

我目前正在使用工具Just code重构代码,该工具显示以下警告之一:

System.Data.SqlClient.SqlParameterCollection.Addstring对象已过时

我还从MSDN中发现:

SqlParameterCollection。添加方法字符串,对象

注意:此API现在已过时

我想知道是否应该重构此代码:

SqlCommand cmdGetIds= oConn.CreateCommand();
cmdGetIds.CommandType = CommandType.StoredProcedure;
cmdGetIds.CommandText = "GetEmployeeId_sp";
cmdGetIds.Connection = oConn;

cmdGetIds.Parameters.Add("@User", "ADMIN");
System.Data.SqlClient.SqlParameterCollection.Addstring,对象为 淘汰的 警告1“System.Data.SqlClient.SqlParameterCollection.Addstring, 对象“”已过时:“AddString parameterName,对象值已过期” 他被弃用了。使用AddWithValueString参数名称,对象 价值。”

如果你看到这个问题,你可以这样解决:

SqlCommand cmdGetIds= oConn.CreateCommand();
cmdGetIds.CommandType = CommandType.StoredProcedure;
cmdGetIds.CommandText = "GetEmployeeId_sp";
cmdGetIds.Connection = oConn;
cmdGetIds.Parameters.AddWithValue("@User", "ADMIN");

刚从msdn网站找到要使用的:AddWithValueString参数名称,对象值