SqlParameterCollection.Add已过时且不推荐使用 [英] SqlParameterCollection.Add is obsolete and deprecated

查看:35
本文介绍了SqlParameterCollection.Add已过时且不推荐使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的代码下出现了波浪线

I am getting squiggly lines underneath the following code

sda2.SelectCommand.Parameters.Add("@from", from);
sda2.SelectCommand.Parameters.Add("@to", to);

鼠标悬停指出 SqlParameterCollection 已过时和上面的Add(String ..)部分已弃用我在互联网上找不到任何可以澄清这一点的信息问题.但是,它确实有效并且没有错误

A mouseover states that SqlParameterCollection is obsolete and Add(String ..) part of the above is deprecated I could not find anything on the internet that clarifies this issue. However, it does work and there are no errors

推荐答案

AddWithValue 是替换"它的方法:

AddWithValue替换采用以下参数的SqlParameterCollection.Add方法一个字符串和一个对象.Add的重载需要一个字符串和一个不推荐使用此对象,因为它可能与SqlParameterCollection.Add重载,它接受一个String和一个SqlDbType枚举值,其中将整数与字符串一起传递可以解释为参数值或对应的SqlDbType值.随时使用AddWithValue通过指定其名称和值来添加参数.

AddWithValue replaces the SqlParameterCollection.Add method that takes a String and an Object. The overload of Add that takes a string and an object was deprecated because of possible ambiguity with the SqlParameterCollection.Add overload that takes a String and a SqlDbType enumeration value where passing an integer with the string could be interpreted as being either the parameter value or the corresponding SqlDbType value. Use AddWithValue whenever you want to add a parameter by specifying its name and value.

MSDN:SqlParameterCollection.AddWithValue方法

这篇关于SqlParameterCollection.Add已过时且不推荐使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆