请问怎样判断记录标题没有重复?

zengye001 2005-09-02 03:58:28

开发环境为sql+asp.net
我建立了一个记录,里面有一个字段为Title,不能重复的。
各位大虾,请问怎样判断记录的标题没有重复呢?
...全文
115 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
menuvb 2005-09-02
  • 打赏
  • 举报
回复
主键索引

~~~~
jimu8130 2005-09-02
  • 打赏
  • 举报
回复
主键索引
真相重于对错 2005-09-02
  • 打赏
  • 举报
回复
from
真相重于对错 2005-09-02
  • 打赏
  • 举报
回复
select count(Title) , Title,... form table group by Title
luoxia001 2005-09-02
  • 打赏
  • 举报
回复

select val=count(title)注:这里最好使用主键或者索引 from *** where title = ***
nnh 2005-09-02
  • 打赏
  • 举报
回复
在sql语句中用in,后判断,如果没有返回,就证明没有相同的记录.不知这样是否可行?
wufeng0524 2005-09-02
  • 打赏
  • 举报
回复
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
luoxia001 2005-09-02
  • 打赏
  • 举报
回复
看到楼主的名字
偶就想到三国志.....^-^
luoxia001 2005-09-02
  • 打赏
  • 举报
回复
select val=count(title)注:这里最好使用主键或者索引 from ***
如果val=0,没重复,1也没重复,>=2,重复

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧