Dear Sanku,
I thing you are using 3 or 4 tier architecture. You will get some idea by using below code.
So you can see the below code:-
Create a class named it as DAL.cs (it will saved in App_code folder). In this dataset we add the namespace Using System.Data;
public DataSet Vacant()
{
SqlConnection con = new SqlConnection(connString);
DataSet ds = new DataSet();
try
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from tname", con);
da.Fill(ds);
return ds; //dataset was returned
}
catch
{
throw;
}
finally
{
ds.Dispose();
con.Close();
con.Dispose();
}
}
Then in the BAL we write the following code for getting the dataset and bind to grid
public DataSet Vacant()
{
DAL Odal = new DAL();
try
{
return Odal.Vacant();
}
catch
{
throw;
}
finally
{
Odal = null;
}
}
then in the .cs page as follows
protected void Page_Load(object sender, EventArgs e)
{
BAL Obal = new BAL();
DataSet ds = new DataSet();
try
{
ds = Obal.vacant();
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.message);
}
finally
{
Obal = null;
}
}
}
Happy Coding
If it helps you or directs U towards the solution,
MARK IT AS ANSWER Sanku, if this helps please login to Mark As Answer. | Alert Moderator