ASP.NET DataTable判断主键是否重复

 protected void LinkButton1_Click( object sender, EventArgs e )
    {
        string UserId = this.TextNumber.Text.Trim( );
        string UserName = this.TextName.Text.Trim( );
        string UserPwd = this.TextPwd.Text.Trim( );
        string UserEmail = this.TextEmail.Text.Trim( );

         object obj = BLLuser.GetData2( UserId );//加上select COUNT(*) from dbo.T_user1 where UserId=@UserId
         int a = ( int ) obj;
        if ( userTable != null && userTable.Rows.Count >= 1 )
        {
            if ( a <= 0 )
            {
                BLLuser.InsertData( UserId, UserName, UserPwd, UserEmail );
            }
            else
            {
                Response.Write( "账号重复了" );
            }
        }
        else
        {
          Response.Write( "没有数据,或者是账号重复了" );
        }
        
        userTable = BLLuser.GetData( );
        this.GridView1.DataSource = userTable;
        this.GridView1.DataBind( );
    }

posted @ 2012-07-27 12:33  blog_yuan  阅读(1419)  评论(0编辑  收藏  举报