How to Search in Gidview using Stored Procedure with DataAdapter?
In this article you can learn how user a Stored Procedure with DataAdapter for searching in Gridview!
I created a table called 'student_details' having 3 columns as 'id','name' and 'rollno'.
In .aspx page i am using Gridview to display student details and adding one textbox and button to search a student name.
Creating a stored Procedure for taking input parameter:
Create Procedure serachdetails1
select * from student_details where name like @name
Above we have to pass one input Parameter as 'name' through a TextBox.
Double click on Serach Button and write below code:
protected void btnseatch_Click(object sender, EventArgs e)
SqlConnection conn = new SqlConnection("Data Source=INTHIYAAZ;Initial Catalog=shakeer;User ID=sa;Password=sa");
SqlCommand command = new SqlCommand("serachdetails1", conn);
command.CommandType = CommandType.StoredProcedure;
string strsearch = "%" + TextBox1.Text + "%";
command.Parameters.Add("@name", SqlDbType.VarChar).Value = strsearch;
SqlDataReader dr = command.ExecuteReader();
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
GridView1.DataSource = ds;
Enter name in textbox and click on Search button.
Below is the image of searching name
Thanks for Reading my article!
Syed Shakeer Hussain