Click here to Skip to main content
14,330,512 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello Friends

I am creating one item form. Please Solve out my problem i don't enter duplicate item name in itemmaster table i am using sql server 2008 and C#. please solve out my problem wia Java script or JQuery
don't write any sql query . i know sql query.

Posted
Updated 8-Oct-19 21:41pm
Comments
Mehdi Gholam 18-Sep-13 9:40am
   
The database language is SQL, so you can't not write SQL.
Giletwala Dhaval 18-Sep-13 9:51am
   
Hello Mehdi
Every time check to database side. it is prefomance issue in future..
ZurdoDev 18-Sep-13 10:35am
   
You have to check the database to know whether it is a duplicate or not. How else would you do it?
Rate this:
Please Sign up or sign in to vote.

Solution 1

If you are concerned not to check database each and every time,then you have to fetch all data in client side during page load.Store them in a javascript array or json object.Then each time you make an entry in your fields,do check for existence of that particular item in fetched data from database.Each time you make an entry in database,reload your page to enable fetching of updated data from database.Then check for existing data each time you make a submit request to database.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

If you want to do it in the client side and not in the server side it is relatively simple to use AJAX from JQuery.

- You could make the 'Submit' button ('Accept' or whatever name you find appropiate) be disabled at page load.

- When the user changes the text in the input control you can detect the text changed event and use AJAX to (in the background) try to download one text/xml document from your site. You can use the text in the input control as part of the query.

- In the server side, when it receives the request for the file (you should of cource trap it as it will refer to non existing page/document) your code should check in the database for the presence or not of that text and return the appropiate content which may simply be one '1' or one '0'.

- On the handler for the event fired when the download has been completed (client side, captured in JQuery) you take that value and decide enabling/disabling the 'submit' button.


It is complex to put it all together but gives the impression of being all done client-side.

The simplest way to do it is with server side data validation.

This piece of code could help you:

Put something like this on the event handler:

LoadMyFile("myfiles/oneXmlFile.xml", function(xml) {
    // This variable contains the parsed xml;
    // ...do something with it here.
});


And make this function available for your page code. sourceDoc is the url and Ready the callback called when the filed download succeeds.

function LoadMyFile(sourceDoc, Ready) {
    $.ajax({
        type: "GET",
        url: sourceDoc,
        dataType: "xml",
        success: function(xml) {
            Ready(xml);
        }
    });
}


p.d. That's how i did something similar some time ago, but creating and testing some code for you could take too long now.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100