Monday, 27 January 2014

Dictionary Search Algorithm to Store Data in Database and Search



One day I was searching the meaning of an English word in dictionary and I got this in less span of time. As we all know that dictionary contains thousands of words and with the help of this we get them easily and quickly.
What if we arrange our data in server in same manner then it will be very easy for our server to find it quickly with the help of this we can save the processing time of server and thus it will be user friendly.
So, here we will design the data in same pattern i.e. we will arrange data in dictionary like. For this assume there is a web application which stores the primary information of user like Name, Email ID, Mobile No. , address and to arrange this like a dictionary we will create 26 tables with name A,B,C,D…up to Z. like this


And now will be insert data in database using jquery in asp.net. To do this first we will create a new project in visual studio 2010 and named it DictionarySearch we will include css and js folder in our project and an index.html file and a Default.aspx page. Like this (do not think about other pages included in this project)
 

In css folder we will create Style.css file to make our page attractive and we will include it in our index.html file. In js folder we will add javascript file to add jquery code to insert data in database.
Now open index.html file and include .css and .js file from css and js folder. Like this





You will have to include some javascript file from internet also so that we add Google javascript file and css you can add your own css instead of Google css file.
With the help of table and textbox and button of html we will create form like this (here button will do insert operation you can rename this submit or insert whatever you want.)

Here is the complete structure of body
<body>
<form id="form1" runat="server">
<div>
<div id="form_div">
            
    <table>
        <tr>
            <td>
                Enter Name of Person:
            </td>
            <td>
                <input class="box" id="Text5" type="text" />
            </td>
        </tr>
        <tr>
            <td>
                Enter Mobil No.:
            </td>
            <td>
                <input id="Text6" class="box" type="text" />
            </td>
        </tr>
        <tr>
        <td>Enter Email ID</td>
        <td>
            <input id="Text1" type="text" /></td>
        </tr>
        <tr>
        <td>Enter Address:</td>
        <td>
            <input id="Text2" type="text" /></td>
        </tr>
        <tr>
        <td>
            <input id="Button1" type="button" value="button" />
        </td>
        <td>
        <span id="message" style=" color:Green; "></span>
        </td>
        </tr>
    </table>
                
            </div>
</div>
</form>
</body>

In javascript file add the following jquery code

Now the problem is that how we will store data in corresponding table? Suppose a name ‘shashi shanker singh’ should be stored in table named ‘S’ and name ‘Amit’ should stored in table named ‘A’. To accomplish this task will use some javascript and find the first alphabet of name of a person like ‘S’ from ‘shashi shnaker singh’ and ‘A’ from ‘Amit’. To do this look at javascript.
document.getElementById('Text5').value.substring(0, 1).toUpperCase()

Since we are getting name of a person from textbox which ID is ‘Text5’
Now we will talk about InsertMethod on Default.aspx file. See the code of this file
 
Here is the complete work flow