Click here to Skip to main content
15,917,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,
I need to search in a web page that will search by a textbox that will get the value or id and then it will search all its relative information from database.So how can I do it?


Best Regards,
Golam kibria
Posted
Comments
[no name] 10-Jun-11 2:53am    
Hi Golam,
Need more clarity, Please add more information like.
1. Are you want to Search from a single table (where ID or Value is available)
or do you mean anything like 'Full Text Search' feature in SOL Server

1 solution

As I Understood Ur Question
I Given Solution Like As Follows

<asp:textbox id="txt_Search" runat="server" width="200px">
<Button ID="btn_Search"  runat="server" Text="Search"  önclick="btn_Search_Click">
<br /><br />
<asp:textbox id="txt_Result" runat="server" textmode="MultiLine" width="200px" height="200px">


SqlConnection con = new SqlConnection("Ur Connection String");
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btn_Search_Click(object sender, EventArgs e)
{
    try
    {
        con.Open();
        string Query =

        "Select UserName from Users Where UserName LIKE
        '%" + txt_Search.Text + "%'";

        SqlDataAdapter da = new SqlDataAdapter(Query, con);
        DataTable DT = new DataTable();
        da.Fill(DT);
        txt_Result.Text = "";
        for (int i = 0; i < DT.Rows.Count; i++)
        {
            txt_Result.Text += DT.Rows[i][0].ToString();
            txt_Result.Text += " ";
        }
        if (txt_Result.Text == "")
            txt_Result.Text = "No Result Found";
    }
    catch (Exception ex)
    {

    }
    finally
    {
        con.Close();
    }
}



Hope This WIll Help You
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900