i want to code a textbox where name are been searched i want to code in a way that if i typed "t" so it should show the names starting with t from the db
thanks
subin
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Madan ShekarRank #428 · 5.9K reputationPosted Feb 19, 2019, 6:44 PM EST
✓ Accepted answer+2
OnTextChanged="SearchByTagButton_Click" />
using System;
using System.Data;
using System.Data.SqlClient;
public partial class AdminSearch : System.Web.UI.Page
SqlCommand cmd = new SqlCommand("Select * FROM Patients WHERE tag_number like @SearchByTagTB+'%'", conn);
try
{
SqlParameter search = new SqlParameter();
search.ParameterName = "@SearchByTagTB";
search.Value = SearchByTagTB.Text.Trim();
cmd.Parameters.Add(search);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
gvPatients.DataSource = dt;
gvPatients.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
//Connection Object Closed
conn.Close();
}
}
}
+2
Salman BegRank #284 · 8.8K reputationPosted Feb 19, 2019, 6:16 PM EST
+1
Hi. You can use like operator to do the same,
declare @test varchar(max);
set @test='t';
select * from table where column1 like @test+'%';
You can use this above line in a stored procedure and pass your textbox value as a parameter. Thanks.
+1
Subin ThomasRank #724 · 3.2K reputationPosted Feb 19, 2019, 7:15 PM EST
0
thanks madan for the code i made some changes and it worked
Madan ShekarRank #428 · 5.9K reputationPosted Feb 19, 2019, 6:44 PM EST
Salman BegRank #284 · 8.8K reputationPosted Feb 19, 2019, 6:16 PM EST
Subin ThomasRank #724 · 3.2K reputationPosted Feb 19, 2019, 7:15 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts