Skip to content

Search whole table in database

mary jean ligas

mary jean ligas

Asked Dec 18, 2012, 7:09 PM EST4 answers
Share
LinkedInX
Hi can anyone direct me on how to do a Seach functionalitieswithin a masterpage..
like this site: http://code.msdn.microsoft.com/vstudio

whenever i type any word in a textbox, it will show all list in result Page..

PLease HELP ME thank you so much!!

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    hi,

      question not clear...

    1.use textchanged event for textbox
    2.connect db table in textchanged event
    3.use storedprocedure to get table values
    4.pass textbox value to storedprocedure as parameter.
    5.parameter value must be like serch

    ex:
    create procedure p
    @p varchar(100)
    as
    begin
    select t from tbl here t like '%@p%'
    end

    then u ll get result.....
    0
  • mary jean ligas
    0
    Can you please help me on how to code this?THanks
    0
  • 0
    ok ill post code....as soon as possible
    0
  • 0
    try this...

    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;


    using



    System.Data;



    public



    partial class Default4 : System.Web.UI.Page


    {


       


    SqlConnection con;


       


    protected void Page_Load(object sender, EventArgs e)


        {


            con =


    new SqlConnection("Database=Admin_db_Student_Details;server=teddy;Trusted_Connection=Yes");


            con.Open();


            Response.Write(con.State.ToString());


           


        }


       


    protected void TextBox1_TextChanged(object sender, EventArgs e)


        {


           


    SqlCommand cmd = new SqlCommand("storedprocedurename", con);


            cmd.CommandType =


    CommandType.StoredProcedure;


            cmd.Parameters.AddWithValue(


    "@pname", TextBox1.Text);


           


    SqlDataAdapter da = new SqlDataAdapter(cmd);


           


    DataTable dt = new DataTable();


            da.Fill(dt);


            TextBox2.Text = dt.Rows[0][0].ToString();



        }


    }

    0