?
Solved

Session

Posted on 2011-10-20
10
Medium Priority
?
198 Views
Last Modified: 2013-12-16
Hello,

I need to add  session table in the loop
this gives me rror. can any one  fix in the below

 Session["prt"] += dt;
0
Comment
Question by:samprg
  • 5
  • 5
10 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37002036
Remove the plus.

 Session["prt"] = dt;

Open in new window

0
 

Author Comment

by:samprg
ID: 37002056
Thanks for response.

I need to plus , because  I want to add more rows ,
I put "Session["prt"] = dt; " in loop
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37002061
Strike that. If this is in a loop, what is the object that you stored in Session["prt"]? Is it a List? A DataSet? Something else?

Since the Session collection stores its "things" as type object, you need to cast the value to the appriate type in order to work with it. For example, if you had stored a List<DataTable> in the Session, you could do:

((List<DataTable>)Session["prt"]).Add(dt);

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:samprg
ID: 37002101

The object is datatable
Gives me error
"Object reference not set to an instance of an object."
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37002233
So you should be able to do:

((DataTable)Session["prt"]).Rows.Add(dt);

Open in new window


assuming "dt" is defined to be of type DataRow. However, since you say you recieved an error related to a null object, are you certain you have inserted a DataTable into the Session using the key "prt"?
0
 

Author Comment

by:samprg
ID: 37002315
Yes "dt" is a DataTable
I used this :
 ((DataTable)Session["prt"]).Rows.Add(dt);
and give me same error
Object reference not set to an instance of an object.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 37002381
Yes "dt" is a DataTable
OK, then you'll need to change the code above a tad because you are trying to pass a DataTable to a function that expects a DataRow! Before you do that, however, you need to verify that you have a valid object in the Session, because it sounds like you don't. Trace through your code prior to this point and make sure you have inserted an instantiated DataTable into the session.

Once you confirm you have inserted a valid object, try using the following:

foreach (DataRow row in dt.Rows)
{
    ((DataTable)Session).Rows.Add(row);
}

Open in new window

0
 

Author Comment

by:samprg
ID: 37002447
I used , same error

((DataTable)Session["prt"]).).Rows.Add(row);
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37002512
same error
Please see the first part of my last comment.
0
 

Author Closing Comment

by:samprg
ID: 37011747
Thabks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question