i have just started learning asp.net and webmatrix a week ago. i read these excellent tutorials http://www.asp.net/web-pages/tutorials/introducing-aspnet-web-pages-2/getting-started and i try to make a similar site that instead of movies have employee records.

here is the code of web page which i made by modifying the given codes in thee tutorials.

My problem is that i want to search for set of records in the table by entering only the date and month field in the search box.and when i click search DOB.it should display all the list of employees details having that DOB.The first search Box works fine as it accepts the complete date in dd/mm/yy but the second one doesn't work.i just want to enter dd/mm .Please help.

//emp.cshtml
 @{
   Layout = "~/_layout.cshtml";
    Page.Title = "NIC Employee DBMS";

    var db = Database.Open("empdata");
    var selectCommand = "SELECT * FROM emptab";
    var searchTerm = "";

    if(!Request.QueryString["searchDOB"].IsEmpty() )
     {
        selectCommand = "SELECT * FROM emptab WHERE dob = @0";
        searchTerm = Request.QueryString["searchDOB"];
     }

     if(!Request.QueryString["searchTitle"].IsEmpty() )  //i think from here to next two-three lines changes
     {                                                                      //are required
        selectCommand = "SELECT * FROM emptab WHERE dob LIKE @0";
        searchTerm    =  Request["searchDOB"] + "%";
     }

    var selectedData = db.Query(selectCommand, searchTerm);
    var grid = new WebGrid(source: selectedData, defaultSort: "dob", rowsPerPage:3);
}

          <h2>EMPLOYEE DETAILS</h2></h2>


                      <form method="get">
                       <div>
                           <label for="searchDOB">DOB to look for:</label>
                           <input type="text" name="searchDOB" value="" />
                           <input type="Submit" value="Search DOB" /><br/>
                            (Leave blank to list all employees.)<br/>
                       </div>

                       <div>
                         <label for="SearchDOB">DOB(dd-mm)no need to write year:</label>
                         <input type="text" name="searchDOB" value="@Request.QueryString["searchDOB"]" />
                         <input type="Submit" value="Search DOB" /><br/>
                       </div>

                   </form>
       <div>

           @grid.GetHtml(
           tableStyle: "grid",
           headerStyle: "head",
           alternatingRowStyle: "alt",
           columns: grid.Columns(
           grid.Column(format: @<a href="~/editemp?id=@item.id">Edit</a>),
           grid.Column("id"),
           grid.Column("name"),
           grid.Column("dob"),
           grid.Column("department"),
           grid.Column("email"),
           grid.Column(format: @<a href="~/deleteemp?id=@item.id">Delete</a>)
          )
         )

      </div>

       <p><a href="~/addemp">Add another employee</a></p>

You want to search the employee on basis of date and month....

so u have to modify ur query accordingly....

    select ID, FName, MobNo, Email, BirthDate
    FROM Tablename
    where
    Day(BirthDate) = day(GETDATE())  and
    month(BirthDate) = month(GETDATE())

ur getdate() should be according to the datetimepicker date and month value....

hope it gives u an idea....

to poojavb:-can you please tell me where to insert your code. i am a super noob. i have just started learning asp.net. if you go to the link mentioned in the above post you will notice that all of the coding part i have copied from the tutorial given in the link.so i don't have much clear concepts. and by the way the date format i am using is dd/mm/yyyy(i am from india and in india we use this format instead of mm/dd/yyyy). Thanks for the above quick reply

U need to insert this query in the place where u want to fetch the employee names...

how are u entering the date....is it a textbox or a datetimepicker???

to poojavb:-can you please tell me where to insert your code. i am a super noob. i have just started learning asp.net. if you go to the link mentioned in the above post you will notice that all of the coding part i have copied from the tutorial given in the link.so i don't have much clear concepts. and by the way the date format i am using is dd/mm/yyyy(i am from india and in india we use this format instead of mm/dd/yyyy)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.