什么是条件声明的错误

时间:2011-06-01 20:57:36

标签: asp.net

SqlConnection con = 
   new SqlConnection
     (@"Data Source=SAMA-PC\SQLEXPRESS;Initial Catalog=advCenter;
          Integrated Security=True");
SqlCommand com1 = new SqlCommand(
     "select visited_link 
      from links 
      where [user_email]=@ue and [visited_link]=@vl",con);
com1.Parameters.AddWithValue("@ue",Convert.ToString(Session["mail"]));
com1.Parameters.AddWithValue("@vl", ImageButton1.ID);
con.Open();
SqlDataReader dr;
dr = com1.ExecuteReader();
if (dr.HasRows)
{
    Label2.Text = "wrong";
}

2 个答案:

答案 0 :(得分:0)

我想你可以试试

command.Parameters.Add("@ue", SqlDbType.NText)
command.Parameters("@ue").Value = Convert.ToString(Session["mail"]);

显式指定列数据类型。

答案 1 :(得分:0)

使用以下内容:

"... and  CAST([visited_link] AS NVARCHAR(MAX))=@vl "

请参阅以下

CAST and CONVERT (Transact-SQL)

HOW TO: Compare Values in NTEXT Field