public class CommClass
{
SqlDataAdapter Da;
DataSet Ds;
DataTable Dt;
SqlCommand Cmd;
SqlConnection Cn;
SqlConnection CnW;
SqlDataReader Dr;
string OnOff;
public CommClass()
{
try
{
Cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Cn"].ConnectionString);
Cn.Open();
OnOff = "On";
}
catch (Exception ex)
{
}
}
public DataSet GetDs(string Crit)
{
DataSet ObjDs = new DataSet();
try
{
Cmd = new SqlCommand(Crit, Cn);
Cmd.CommandTimeout = 0;
Da = new SqlDataAdapter(Cmd);
Da.Fill(ObjDs);
}
catch (Exception ex)
{
}
return ObjDs;
}
this Code is in common class in App_Code..
First of all declare Your all variables in common class
then in constructor make connection(with connctionstring which is in web.config
then in get ds method
(This is what You want to learn)
create new dataset,new command in which You can pass query,connection
than new dataadapter andin that pass command(which have query and connection already!!!)
so You can Fill ds
and return ds
in You aspx.cs
page You have To just write
CommClass objCls=new CommClass();
ds=objCls.GetDs("Select * from EmployeeMst");
Enjoy...
HAPPY CoDING:)