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
- make id column
primary key
, when insert exception if duplicated - you can use auto increment id, don't need check id exit or not. database handle that
- if can't above, run select statement or stored procedure check whether id exist or not.
Comments
Post a Comment