Showing posts with label filter data. Show all posts
Showing posts with label filter data. Show all posts

10 September 2011

GridView data filter with StoredProcedure

SqlCommand cmd=newSqlCommand();
SqlConnection con = new SqlConnection("..your connection string....");
//Data Source=satya;Initial Catalog=MyDB;Persist Security Info=True;User ID=sa;Password=sa123
SqlDataAdapter da=newSqlDataAdapter();
DataSet ds=newDataSet();
cmd.Parameters.Clear();

cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_getall";
cmd.Connection = con;
cmd.Parameters.Add("@p", SqlDbType.VarChar, 20).Value = txtSearch.Text;

da = newSqlDataAdapter(cmd);
da.Fill(ds);
DataView dv = ds.Tables[0].DefaultView;

dv.RowFilter = "eName like '" + mr+"'";
gvsearch.DataSource = dv;
gvsearch.DataBind();

create proc sp_getall
as
begin
select*from tblemp
end

------------------------------------

cmd.CommandText = "select * from user_master";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
dr = cmd.ExecuteReader();
//table, ExecuteScalar - single value object type, ExecuteNonQuery - Count
gv1.DataSource = dr;
gv1.DataBind();
con.Close();