简体   繁体   中英

Pass DataTable To Another Class - ASP.Net

I would like to pass a datatable to the DataAccessLayer from aspx.cs page. DAL is another project and CountryDal is a class file in it. Unable to do it using the session object. What is the proper way to acheive this.

ASPX.CS

private countryDAL objDAL = new CountryDAL();

protected void btnSave_Click(object sender, EventArgs e)
{
  //code...
  Session["tbl"] = dt;    //dt is a datatable with some data
  objDAL.SaveTable();
}

DAL

public void SaveTable()
{
  DataTable dtSave = (DataTable)Session["tbl"];

  //code.....
}

Inject it into the method:

public void SaveTable(DataTable dtSave)

so then, when you call it, just do this:

objDAL.SaveTable(dt);

and you can get rid of this line:

Session["tbl"] = dt;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM