2011-06-01 88 views
0
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][email protected] and [visited_link][email protected]",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"; 
} 
+0

你什么样的错误(如果有的话)? – 2011-06-01 20:59:26

+0

错误信息会有帮助。 – JasonCoder 2011-06-01 21:00:29

+0

错误消息是:数据类型ntext和nvarchar在等于运算符中不兼容。但如果我做了一个没有和visited_link = @ vl的条件,这个陈述变得真实 – semsema 2011-06-01 21:03:23

回答

0

我想你可以尝试

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

明确指定列的数据类型。

+0

就像Bala R说的那样,你需要指定类型。但是,根据您添加的内容。无论如何,我不确定使用ntext列类型是否合适。我认为如果你将数据库模式从ntext更改为nvarchar(max)(这可能仍然超过链接所需的数量),则不需要指定类型,它将起作用。指定类型不会受到伤害,并且可能是一种很好的做法。 – 2011-06-01 21:13:37