.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

How to Search in Gidview using StoredProcedure with DataAdapter?

Posted By:Syed Shakeer Hussain       Posted Date: August 22, 2009    Points: 25    Category: ASP.NET    URL: http://www.dotnetspark.com  

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
 @name varchar(50)
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

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend