本帖最后由 dongganxingkong 于 2011-09-22 15:18:02 编辑

解决方案 »

  1.   

    insert into 密码表(用户名,密码) select distinct "admin","12345" from PASSWORDTBL
    where 用户名<>'admin'可将admin、12345修改为变量
      

  2.   


    if not exists(select 1 from tb where UserID='X275' 
    insert into tb(UserID,Password) select 'X275','123456' 程序代码:
            private bool CheckUser(string UserID, string Paswd)
            {
                SqlConnection cnn = new SqlConnection(....);
                SqlCommand cmd=new SqlCommand();            //先验证是否存在此用户,若不存在则插入,并返回TRUE,若存在则验证密码不对则返回false; 
     
            }
      

  3.   

    if not exists(select 1 from 密码表where 表ID ='admin')
    begin 
      insert into 密码表 values('admin','12345')
    end
    if exists(select 1 from 密码表where 表ID ='admin')
    begin 
       return 
    end
      

  4.   

    insert into
     PASSWORDTBL(用户名,密码) 
    select
     'admin','12345' 
    from
     密码表 t
     where
    not exists(select 1 from PASSWORDTBL where 用户名='admin' and 用户名=t.用户名 ) 
      

  5.   

    if not exists(select * from 用户表)
     
      

  6.   

    --创建测试表
    create table PASSWORDTBL(用户名 nvarchar(20),密码 varchar(20))
    insert into PASSWORDTBL select 'aaa','bbb'
    go
    --实现楼主的需求:
    insert into PASSWORDTBL(用户名,密码)
    select 'admin','12345' 
    from PASSWORDTBL
    where not exists(select 1 from PASSWORDTBL where 用户名='admin')
    go
    --检验
    select * from PASSWORDTBL
    /*
    用户名                  密码
    -------------------- --------------------
    aaa                  bbb
    admin                12345(2 行受影响)*/
    drop table PASSWORDTBL
      

  7.   

    --创建测试表
    create table PASSWORDTBL(用户名 nvarchar(20),密码 varchar(20))
    insert into PASSWORDTBL select 'aaa','bbb'
    go
    --实现楼主的需求:
    insert into PASSWORDTBL(用户名,密码)
    select 'admin','12345' 
    from PASSWORDTBL
    where not exists(select 1 from PASSWORDTBL where 用户名='admin')
    go
    --再次插入
    insert into PASSWORDTBL(用户名,密码)
    select 'admin','678910' 
    from PASSWORDTBL
    where not exists(select 1 from PASSWORDTBL where 用户名='admin')
    go
    --检验
    select * from PASSWORDTBL
    /*
    用户名                  密码
    -------------------- --------------------
    aaa                  bbb
    admin                12345(2 行受影响)*/
    drop table PASSWORDTBL