当前位置: 代码迷 >> .NET Framework >> C# 中SqlParameter种使用的一些困惑
  详细解决方案

C# 中SqlParameter种使用的一些困惑

热度:85   发布时间:2016-05-02 00:09:53.0
C# 中SqlParameter类使用的一些困惑。
以下代码
cmd.CommandText = "select * from tMS where [email protected]";
cmd.Parameters.Add(new SqlParameter("@UserName", txtUserName.Text));

第二行中相差一个 @ 符号
cmd.Parameters.Add(new SqlParameter("@UserName", txtUserName.Text));
cmd.Parameters.Add(new SqlParameter("UserName", txtUserName.Text));

这两个都能运行,为什么呢?谁能解释一下?有区别么?
那个 @ 重不重要?
------最佳解决方案--------------------
[email protected],要不找不到了,对参数赋值源代码如下

public override void set_ParameterName(string value)
{
    if ((!ADP.IsEmpty(value) && (value.Length >= 0x80)) && (('@' != value[0])