How to Search data in Gidview using StoredProcedure ?

Syedshakeer
Posted by Syedshakeer under C# category on | Views : 3318
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)
)
as
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");
conn.Open();
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();
dr.Close();
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}

Comments or Responses

Login to post response