|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
INSERT before checking duplicate valuesHi
I am inserting 2 text values from user input. I wanted ot check if there is any duplicate text value before I insert into columns...which is best way to avoid duplicate valies....constraints or check in INSERT statement.....any idea any pointes thanks n advace SAgar Select Count(*) FROM tableName WHERE yourColumnName='" & txtUserInput & "';"
Anything greater than 0 means its already in the set Show quote "Sagaar" <Sag***@discussions.microsoft.com> wrote in message news:C7C7869E-605B-4458-AB56-CD1F10984B1D@microsoft.com... > Hi > > I am inserting 2 text values from user input. I wanted ot check if there > is > any duplicate text value before I insert into columns...which is best way > to > avoid duplicate valies....constraints or check in INSERT statement.....any > idea any pointes > > thanks n advace > > SAgar On Sat, 15 Apr 2006 02:22:01 -0700, Sagaar <Sag***@discussions.microsoft.com>
wrote: >Hi If the value in a table should be unique, there should be a constraint set on> >I am inserting 2 text values from user input. I wanted ot check if there is >any duplicate text value before I insert into columns...which is best way to >avoid duplicate valies....constraints or check in INSERT statement.....any >idea any pointes > >thanks n advace > >SAgar it. The reasoning behind this is you may want to access the table from another application at a later time. If you depend on code in the application to enforce uniqueness, you or another developer may forget to code the test for unique value insertion and update. If you are using DataAdapters/DataSets to access the table you can set the DataColumn's Unique property to true and save a round trip to the DB when testing the value for uniqueness. Good luck with your project, Otis Mukinfus http://www.arltex.com http://www.tomchilders.com Thanks...
Actually I am getting my 2 columns from WebServices and then add these to Datagrud column during runtime. MY requirement was to get from webservice then add to list but also store locally these columns in table....while doing insert I want to check if data is already there or not.....if its there I dont want to do any isert else I want to insert. How do I implement this? in ASP.Net using C#?? even if i do a check before I do insert is okk... thx in advance Regsd Sagar Show quote "Otis Mukinfus" wrote: > On Sat, 15 Apr 2006 02:22:01 -0700, Sagaar <Sag***@discussions.microsoft.com> > wrote: > > >Hi > > > >I am inserting 2 text values from user input. I wanted ot check if there is > >any duplicate text value before I insert into columns...which is best way to > >avoid duplicate valies....constraints or check in INSERT statement.....any > >idea any pointes > > > >thanks n advace > > > >SAgar > > If the value in a table should be unique, there should be a constraint set on > it. The reasoning behind this is you may want to access the table from another > application at a later time. If you depend on code in the application to > enforce uniqueness, you or another developer may forget to code the test for > unique value insertion and update. > > If you are using DataAdapters/DataSets to access the table you can set the > DataColumn's Unique property to true and save a round trip to the DB when > testing the value for uniqueness. > > Good luck with your project, > > Otis Mukinfus > http://www.arltex.com > http://www.tomchilders.com > On Sat, 15 Apr 2006 14:46:02 -0700, Sagaar <Sag***@discussions.microsoft.com>
wrote: Show quote > I understood your original post, but I don't think you understood my answer to>Thanks... > >Actually I am getting my 2 columns from WebServices and then add these to >Datagrud column during runtime. > >MY requirement was to get from webservice then add to list but also store >locally these columns in table....while doing insert I want to check if data >is already there or not.....if its there I dont want to do any isert else I >want to insert. > >How do I implement this? in ASP.Net using C#?? > >even if i do a check before I do insert is okk... > >thx in advance > >Regsd >Sagar > [snip] your question. I simply told you what some of your options are. Now you must decide how you will do it. You may have to do some research to determine what suits your situation best. If you feel you should do this the way you describe, then you should follow OHM's good and valid advice. There is no rule against placing unique constraints on two columns in a table (or more). Nor is there a rule against doing a check before the insert. Good luck with your project, Otis Mukinfus http://www.arltex.com http://www.tomchilders.com |
|||||||||||||||||||||||