here is the code of web page which i made by modifying the given codes in thee tutorials
//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>
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.
to mattsdotnet:- i copied your code but i am getting this error
Server Error in '/' Application.
Compilation Error
Description:
An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'searchCommand' does not exist in the current context
Source Error:
Line 15: {
Line 16:
Line 17: searchCommand = String.Format(
Line 18: "SELECT * FROM emptab WHERE Month(dob) = Month({0}) AND Day(dob) = Day({0})",
please someone help me.its urgent.i have do the same thing in my college lab exam.actually what i intend to do is kind of Facebook b'day notification.when the date (here the system date) matches with those in the records, then those records should come in
a tabular manner.Pls help me ASAP
s_deep
Member
2 Points
6 Posts
How to SEARCH for a set of records by enterning dd/mm(leaving year)
Jun 22, 2012 06:39 AM|LINK
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
//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>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.
MattsDotNetU...
Contributor
3178 Points
515 Posts
Re: How to SEARCH for a set of records by enterning dd/mm(leaving year)
Jun 22, 2012 02:03 PM|LINK
This should work. You need to break out the month and day checks seperatly in this case:
if(!Request.QueryString["searchTitle"].IsEmpty() ) { searchCommand = String.Format( "SELECT * FROM emptab WHERE Month(dob) = Month({0}) AND Day(dob) = Day({0})", Request["searchDOB"]); searchTerm = ""; }s_deep
Member
2 Points
6 Posts
Re: How to SEARCH for a set of records by enterning dd/mm(leaving year)
Jun 22, 2012 03:26 PM|LINK
to mattsdotnet:- i copied your code but i am getting this error
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'searchCommand' does not exist in the current context
Source Error:
Line 15: { Line 16: Line 17: searchCommand = String.Format(Line 18: "SELECT * FROM emptab WHERE Month(dob) = Month({0}) AND Day(dob) = Day({0})",sushanth009
Contributor
6243 Points
1168 Posts
Re: How to SEARCH for a set of records by enterning dd/mm(leaving year)
Jun 22, 2012 03:28 PM|LINK
Think according to your code it is selectCommand and not
searchCommands_deep
Member
2 Points
6 Posts
Re: How to SEARCH for a set of records by enterning dd/mm(leaving year)
Jun 22, 2012 03:39 PM|LINK
to sushant009
still not working
.pls tell me how to post images show that it will be more clear to you
i entered the date : 03-05 in the box and when i click on searchDOB
then no record was displayed(but there is a record in the database with that DOB)
s_deep
Member
2 Points
6 Posts
Re: How to SEARCH for a set of records by enterning dd/mm(leaving year)
Jun 25, 2012 05:35 AM|LINK
please someone help me.its urgent.i have do the same thing in my college lab exam.actually what i intend to do is kind of Facebook b'day notification.when the date (here the system date) matches with those in the records, then those records should come in a tabular manner.Pls help me ASAP