[英]How to pass SQL results from one page to another C# asp.net
I am building a web application that will have multiple form pages that will be used to extract data from a database and export to excel. 我正在构建一个Web应用程序,它将具有多个表单页面,这些页面将用于从数据库中提取数据并导出到excel。
To save me reproducing the same code to export to excel I have produced an output page containing a gridview and a button that onclick runs my export to excel code. 为了避免重现要导出到excel的相同代码,我制作了一个输出页面,其中包含一个gridview和一个onclick将我的导出导出到excel代码的按钮。
I pass the results of my sql query or stored procedure from the form page to the output page by storing a datatable in a session object and setting that to be the datasource of the gridview. 我通过将数据表存储在会话对象中并将其设置为gridview的数据源,将sql查询或存储过程的结果从表单页传递到输出页。
However I do not know how big some of the results will be or how many users will be using these forms at any one time, so I anticipate a session object isnt the best idea. 但是,我不知道任何时候会有多少结果,或者有多少用户将同时使用这些表单,因此我预计会话对象不是最好的主意。
Any thoughts would be greatly appreciated, thanks. 任何想法将不胜感激,谢谢。
C# code from one of the Form pages 表单页面之一中的C#代码
DataTable myDataTable = new DataTable();
string myConnectionString = //connectionstring text
SqlConnection myConnection = new SqlConnection(
ConfigurationManager.ConnectionStrings[myConnectionString].ConnectionString);
string mySQL = //built sql query
SqlDataAdapter myDataAdaptor = new SqlDataAdapter(mySQL,myConnection);
using(myDataAdaptor)
{
myDataAdaptor.Fill(myDataTable);
}
Session["Output"] = myDataTable;
Response.Redirect("output.aspx");
C# code on output page 输出页面上的C#代码
protected void Page_Load(object sender, EventArgs e)
{
gvOutput.DataSource = Session["Output"];
gvOutput.DataBind();
}
You basically have to store your value out of the scope of page, session, cache with sessionid as key, serializing and deserializing the value are few of them. 基本上,您必须将值存储在页面,会话,以sessionid为键的缓存范围之外,对值进行序列化和反序列化的方法很少。
For less accessible page session is fair enough, how about inproc session having this data for frequently accessed page? 对于访问较少的页面会话是足够公平的,对于具有频繁访问页面的数据的inproc会话又如何呢?
This basically is a design choice which should be taken into consideration depending on traffic on the page, predicted size of data and etc. 这基本上是一种设计选择,应根据页面上的访问量,预测的数据大小等加以考虑。
Session is precious and can hamper performance if not managed well. 会话很宝贵,如果管理不当,则会影响性能。 Imagine your query returning huge data as your application grows.
想象一下,随着应用程序的增长,查询将返回大量数据。
To keep it short, if your page is not highly accessed and session data you are storing is appropriate to your hardware session is a fair choice. 简而言之,如果您的页面访问量不高,并且要存储的会话数据适合您的硬件会话,则是一个不错的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.