会话内存中的数据表没有列
我试图检索我放入会话变量中的数据表,但是当我这样做时,似乎没有列...
我之前在 VB.NET 中做过此操作,现在使用 C#,并且它工作得很好,据我所知,除了明显的语法变化之外,代码没有任何变化。
编辑:
当我查看数据可视化窗口时,dt(第 2 部分)变量具有正确的数据,但我注意到与数据表关联的其他属性不存在。当我用鼠标将鼠标悬停在看起来正常的数据表上时,它看起来如下所示:“dt ----- {System.Data.DataTable}”,但在我正在处理的类中,它看起来像“dt -----” {}”。另外,在我将会话变量返回到 dt 后,我克隆它(dtclone = dt.clone(); ),并且克隆在数据可视化器中为空......到底是什么!
编辑2:
我现在还尝试将第一个数据表转换为数据集,将其放入会话变量中,然后将其恢复回类中的数据表。
我开始怀疑这是否是一个问题:
dt.Load(sqlReader);
数据确实在这一步之后出现在数据集可视化器中,但在克隆后不会出现。
代码如下。
非常欢迎大家的帮助!
预先感谢
Chris
1) Webhandler 中的 SQL 命令,其结果填充要放入会话变量中的数据表。
DataTable dt = new DataTable();
SqlDataReader sqlReader= default(SqlDataReader);
SqlDataAdapter sqlAdapter = new SqlDataAdapter();
sqlReader = storedProc.ExecuteReader(CommandBehavior.CloseConnection);
dt.Load(sqlReader);
System.Web.HttpContext.Current.Session["ResultsTable"] = dt;
2)类中对表进行计算的部分代码:
DataTable dt = (DataTable)HttpContext.Current.Session["ResultsTable"];
Im trying to retrieve a datatable that I put into a session variable, however when i do it apears that there are no columns...
I have done this before in VB.NET, I'n now using C#, and it worked perfectly, and as far as i can see there is no change in the code other than the obvious syntax changes.
EDIT:
The dt (in part 2) variable has the right data when i look in the data visulization window, but i have noticed that the other properties associated with a datatable are abscent. When i hover over a normal looking datatable with my mouse it looks like the following: " dt ----- {System.Data.DataTable}" but in the class im working on it just looks like "dt ----- {}". Also, after I return the session variable into the dt I clone it (dtclone = dt.clone(); ) and the clone is empty in the data visulizer.... what on earth!
EDIT 2:
I have now also tried converting the first datatable to a dataset, putting this in the session variable, and recoverting it back to a datatable in the class.
Am starting to wonder if it is a probelm with:
dt.Load(sqlReader);
The data does appear after this step though in the dataset visualiser, but not after being cloned.
Code below.
All help very welcome!
Thanks in advance
Chris
1) SQL command in a webhandler, the results of which populate the datatable to be put into the session variable.
DataTable dt = new DataTable();
SqlDataReader sqlReader= default(SqlDataReader);
SqlDataAdapter sqlAdapter = new SqlDataAdapter();
sqlReader = storedProc.ExecuteReader(CommandBehavior.CloseConnection);
dt.Load(sqlReader);
System.Web.HttpContext.Current.Session["ResultsTable"] = dt;
2) Part of the code in a class which performs calculations on the table:
DataTable dt = (DataTable)HttpContext.Current.Session["ResultsTable"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你在设置Session Var后调用DataTable dispose了吗?
因为如果你这样做,解决方案是这样的:
did you call DataTable dispose after setting Session Var?
Because if you do this, solution is like this: