Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to search values from table. I have textbox and button. when i enter string in textbox and press button all matching records from table should display. Please help me.
Posted
Updated 5-Jul-12 20:31pm
v2

What is this?

You tagged it C# and SQL. How you want to search.

You must refer:
How to ask a good question?[^]

ans also Some guidelines for posting questions in the forums[^]

Before posting any question give a try by your side first. Visit google, find some solutions and if you get stuck'd somewhere then post your question here.

[EDIT]
Refer: Search into Textbox and Bind Gridview using Asp.net[^]

Have a look on google[^] for same.

Always try google first, then post your questions here. Google is better option than anything else.

Happy coding.!
 
Share this answer
 
v2
Comments
Abhinav S 6-Jul-12 2:29am    
5.
I guess the OP is looking for more information on the Where clause
Prasad_Kulkarni 6-Jul-12 2:31am    
I appreciate your comment and answer sir. But how can one get from such one line question what he wants.
Abhinav S 6-Jul-12 2:37am    
Well. yeah that is true.
You need to learn about the WHERE clause[^] in SQL.

A number of conditions like BETWEEN, LIKE etc provide ways to write filter conditions in a query.

You will need to do some reading on SQL to learn more about searching / filtering values.
 
Share this answer
 
v2
Comments
Prasad_Kulkarni 6-Jul-12 2:44am    
+5 :)
Abhinav S 6-Jul-12 2:48am    
Thank you.
hi try this
create stored procedure

SQL
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go



ALTER PROCEDURE [dbo].[usp_SearchRoomDetails]
@RoomNo varchar(50)


AS
BEGIN

    SET NOCOUNT ON;


    SELECT * from RoomDetailsTab  where RoomNo=@RoomNo
END




and call this sp in page


protected void Search_Click(object sender, ImageClickEventArgs e)
    {
        string RoomNo = "";
        RoomNo = txtRoomNo.Text;
        
        SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());

        cnn.Open();
        SqlCommand cmd = new SqlCommand();

        cmd.Connection = cnn;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "usp_SearchRoomDetails";

        SqlParameter pRoomNo = new SqlParameter("@RoomNo", SqlDbType.VarChar, 50);
        pRoomNo.Value = RoomNo;
        cmd.Parameters.Add(pRoomNo);
      


        DataTable dt = new DataTable();

        SqlDataAdapter da = new SqlDataAdapter(cmd);


        da.Fill(dt);


        if (dt.Rows.Count > 0)
        {
//if u want to display searched record in textbox
            txtRNo.Text = dt.Rows[0]["RoomNo"].ToString();
            txtDetails.Text = dt.Rows[0]["Details"].ToString();
           

           
        }
        if (dt.Rows.Count == 0)
        {
//if record is empty will show message
            Response.Write("No result found");
        }
        cnn.Close();
    }




try this
happy coding..
 
Share this answer
 
Comments
Prasad_Kulkarni 6-Jul-12 2:46am    
5'ed
ythisbug 6-Jul-12 2:47am    
thanks prasad

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