Friday, 15 March 2013

c# - Prevent Duplicate Entry in Data table -



c# - Prevent Duplicate Entry in Data table -

i using info table store employee details. need prevent duplicate entry.

code behind:

try { strserverselectedname = txtservername.text; string dcurrentdatetime = convert.tostring(datetime.now.tolocaltime()); datatable ds1 = new datatable(); datarow dr1 = ds1.newrow(); iserverselectedid = convert.toint32(session["selectedserverid"].tostring()); ds1 = datalayer.getservicedetails(iserverselectedid); ds1.columns["servicename"].unique = true; string strservicename = txtservicename.text; string strdescription = txtareadescription.text; string username = usernameshown.text; datalayer.insertsingleservice(iserverselectedid, username, dcurrentdatetime, strservicename, strdescription); ds1 = datalayer.getservicedetails(iserverselectedid); grdserverdetails.datasource = ds1; grdserverdetails.databind(); } catch(exception ex) { alert.show(ex.message); }

i using unique key prevent duplicate values in code behind won't help me recover issue. in advance

you can set primarykey in datatable or constraints

c# sql asp.net

No comments:

Post a Comment