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>