I am trying to create forms where the user can input text in up to 3 forms. Each of the forms will correspond to columns in an SQL Server CE database table. Based on the text input into the forms, the page will display all rows that contain all of the specified text (with null values being treated as wildcards).
I have this working fine for 1 form. The form text is being assigned as a value for a variable and passed between the pages no problem. I am just not sure how in include the 2 other columns in the query.
Here is the code for the input page with the forms:
@{
var formValue1 = Request.Form["FN"];
var formValue2 = Request.Form["LN"];
var formValue3 = Request.Form["CPNY"];
if (IsPost)
{
Response.Redirect("DisplaySearch.cshtml?firstname=" + formValue1);
Response.Redirect("DisplaySearch.cshtml?lastname=" + formValue2);
}
}
<form action="" method="post">
First Name:<input type="text" ID="FN" name="FN" value=""></input><br>
Last Name:<input type="text" ID="LN" name="LN"></input><br>
Company:<input type="text" ID="CPNY" name="CPNY"></input>
<br>
<input type="submit" value="Search"></input></form>
Here is the code for the display page:
@using WebMatrix.Data
@{
var Keyword1 = Request.QueryString["firstname"]; //Retrieves passed variable from the database search page for First Names
var Keyword2 = Request.QueryString["lastname"]; //Retrieves passed variable from the database search page for First Names
var Keyword3 = Request.QueryString["company"]; //Retrieves passed variable from the database search page for First Names
var db= Database.Open("Orientation");
var sqlQ = "SELECT * FROM Orientation WHERE FirstName LIKE @0";
var data = db.Query(sqlQ, "%" + Keyword1 + "%");
}
<div class="content-box-main">
<ol>
@foreach(var row in data){
<li>
@row.LastName, @row.FirstName, @row.MiddleName, @row.Email, @row.Company, @row.Date
</li>
}
</ol><br>
</div>
Help is greatly appreciated! I am a noob to create web applications and my only programming experience up to 2 weeks ago was the odd VBA macro in Office. I will also mention again, I am using WebMatrix and SQL Server CE. I know that there are some limitations with SQL Server CE, although I enjoy the ease of use for me being a noob. If anyone has any suggestions for different SQL Server program to use, I would be open to hearing them.
Thanks!
James