How to Search data in Gidview using StoredProcedure ?

Posted by Syedshakeer under C# category on | Views : 3259
How to Search in Gidview using Stored Procedure with DataAdapter?
I created a table called 'student_details' having 3 columns as 'id','name' and 'rollno'.

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("Connection String");
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;

Comments or Responses

Login to post response