Reputation: 10777
I am new to asp.net and trying to do simple things first. Now i am trying to make a simple library database. In my scenario user enters the title that he needs to search and then clicks search button. Here is the screenshot of my simple user interface:
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class Pages_Search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void bSearchButton_Click(object sender, EventArgs e)
{
string searchedItem = tSearchBox.Text;
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\Users\\SUUSER\\Documents\\Visual Studio 2010\\Projects\\Library\\LibWebSite\\App_Data\\LibDatabase.mdf;Integrated Security=True;User Instance=True";
Int32 verify;
string query1 = "";
if (SearchBy.SelectedValue == "Search by title")
{
query1 = "Select count(*) from Items where Title='" + tSearchBox.Text + "'";
}
}
}
My question is, my query finds the number of items with that title, but does not print each item to the screen. How can i print out the search results to the screen? I mean how can i show the search results in another web page? I appreciate any helps.
Thanks
Upvotes: 0
Views: 544
Reputation: 7626
Change your query to:
"Select Title,count(1) from Items where Title='" + tSearchBox.Text + "'";
Upvotes: 0
Reputation: 3982
Tutorials such as this should help:
http://www.codeproject.com/Articles/8659/Mastering-ASP-NET-DataBinding
Upvotes: 1