各位老大,我是刚学asp.net,一个简单问题,我在编写注册代码,我不想要相同用户名插入数据库,如何做,给出代码,谢谢,,

解决方案 »

  1.   

    数据库给这个字段建一个唯一索引.insert的时候勤快的话,检查一下是否重复,懒的话,直接
    try遇到-2627错误就报重复信息.
      

  2.   

    http://chs.gotdotnet.com/quickstart/aspplus/doc/webdataaccess.aspx
      

  3.   

    给用户名字段加上unique约束
    或者:
    if not exist (select * from usertable where username='...') 
    insert into usertable values(...)
      

  4.   

    可以使用ajax来判断数据库是否有该拥护
    然后提示
    目前大部分都市这么开发的
      

  5.   

    UserID 已经设成primary key 应该不会插入重复值呀,,