开发环境为sql+asp.net 
我建立了一个记录,里面有一个字段为Title,不能重复的。
各位大虾,请问怎样判断记录的标题没有重复呢?

解决方案 »

  1.   

    select val=count(title)注:这里最好使用主键或者索引 from ***
     如果val=0,没重复,1也没重复,>=2,重复
      

  2.   

    if (GetRsCount("Table where title='"+Title.Text+"'")>0)
    {
       // 标题不能重复
       return;
    }/// <summary>
    /// 获得表记录数
    /// </summary>
    /// <param name="table_name">表名或者表名+条件,GetRsCount("t_user where id="+Request["id"])</param>
    /// <returns></returns>
    public int GetRsCount(string table_name)
    {
    string strSql;
    int intCount;
    Open();
    strSql="select count(*) from "+table_name;
    SqlCommand cmd=new SqlCommand(strSql,cn);
    intCount=(int)cmd.ExecuteScalar();
    cn.Close();
    return intCount;
    }————————————————————————————————
    DotNet中华网,我们最原创:www.aspxcn.org
      

  3.   

    在sql语句中用in,后判断,如果没有返回,就证明没有相同的记录.不知这样是否可行?
      

  4.   


    select val=count(title)注:这里最好使用主键或者索引 from *** where title = ***
      

  5.   

    select count(Title) , Title,... form table  group by Title