sql server - Check for duplicate records in sql database using vb.net -


assuming table consist of 2 columns id , name.

and assume have stored procedure working on vb.net inserts rows database.

but system needs check if id entered in textbox exists in database when add button click.

create procedure addofficeequipmentprofile ( @oe_id      varchar(11),     @oe_category        char(3) =null,       @oe_subcategory char(3)=    null,        @oe_name        varchar(35)=null,        @oe_user        varchar(35)=null,    @oe_brand       varchar(15)=null,    @oe_model       varchar(35)=null,    @oe_specs       varchar(1000)=null,      @oe_serialno        varchar(35)=null,    @oe_propertyno  varchar(35)=null,    @oe_macaddress  varchar(100)=null,       @oe_static_ip       varchar(15)=null,    @oe_vendor      varchar(35)=null,    @oe_purchasedate    smalldatetime,       @oe_warrantyinclusiveyear   int=null,    @oe_warrantystatus  char(2)=    null,    @oe_status      varchar(15)=null,        @oe_dept_code   char(3)=    null,    @oe_location_code   char(8)=    null,        @oe_remarks     varchar(1000)=  null )  insert tblofficeequipmentprofile (oe_id, oe_category, oe_subcategory, oe_name, oe_user, oe_brand, oe_model, oe_specs, oe_serialno, oe_propertyno, oe_macaddress, oe_static_ip, oe_vendor, oe_purchasedate, oe_warrantyinclusiveyear, oe_warrantystatus, oe_status, oe_dept_code, oe_location_code, oe_remarks )  values (@oe_id, @oe_category, @oe_subcategory, @oe_name, @oe_user, @oe_brand, @oe_model,  @oe_specs, @oe_serialno, @oe_propertyno, @oe_macaddress, @oe_static_ip, @oe_vendor, @oe_purchasedate, @oe_warrantyinclusiveyear, @oe_warrantystatus, @oe_status, @oe_dept_code, @oe_location_code, @oe_remarks)  go 

few things can do

  1. make id column primary key, when insert exception if duplicated
  2. you can use auto increment id, don't need check id exit or not. database handle that
  3. if can't above, run select statement or stored procedure check whether id exist or not.

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -