简体   繁体   English

将数据表传递给另一个类-ASP.Net

[英]Pass DataTable To Another Class - ASP.Net

I would like to pass a datatable to the DataAccessLayer from aspx.cs page. 我想将数据表从aspx.cs页面传递到DataAccessLayer。 DAL is another project and CountryDal is a class file in it. DAL是另一个项目,而CountryDal是其中的一个类文件。 Unable to do it using the session object. 无法使用会话对象执行此操作。 What is the proper way to acheive this. 实现此目的的正确方法是什么?

ASPX.CS 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 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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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