Forum Xamarin.Forms

Prevent duplicate my user name Sql server database

sjinsjin Member ✭✭
I am using Userid using Api to connect Sql server database. But when i insert my username, duplicated username input to database column . Should i prevent my Xamarin. Form or api ?
Please advice me how to prevent Username duplication?


  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Is Username primary key? If you set the Username to primary key, Username must keep unique and not null, If you set the duplicated username, You can add a ID in your model, set the ID to the primary key and auto-Increment

      public class Prijem
        [PrimaryKey, AutoIncrement]
        public int ID { get; set; }
        public string Username { get; set; }
        public string FirmName { get; set; }
        public string ItemCode { get; set; }
        public string Count { get; set; }

    If you set the Username to Unique, please remove it.

  • sjinsjin Member ✭✭
    I have different primary key which is id,
    I want to make my username which is not duplicated key and unique even though id is primary key. Please help me ! Thank you
  • JohnHJohnH GBMember ✭✭✭✭✭
    You can add a unique constraint on that column in sql server.
Sign In or Register to comment.