Reputation: 3281
I want to store DataTable in Cookies but i can't find any solution.
i have try some code but can't find any solution.
HttpCookie dt = new HttpCookie("dt");
How to add datatable in this dt.?
Upvotes: 2
Views: 4015
Reputation: 45
Like answered before a cookie can store any string.
If i were you i would avoid storing it but if you really need to do so , I'd do something like this :
Assume you have the following Data-table:
Col A Col B Col C
A B C
D E F
and so on...
I'd Store the cookie in the following way: A,B,C;D,E,F; ... so on for as many rows that you have.
Thus you can see each row is delimited using a ';' and each column using a ','.
Later when i wish to get back the table from cookie , ill get the above string (A,B,C;D,E,F;)
I'd now have to reconstruct the table but would not need to make any DB calls.
I'd first do a String.split(";"); to get all rows of a data-table
Then for each row in Above array do a String.split(",") to get each value in each row .
As you can see I haven't written the entire code but seems like something any one caould do .
Also you can choose any column and row delimiter of your choice.
I'd suggest this approach only if your table isn't too large.
Upvotes: 0
Reputation: 136
Cookies can store values only of type String. You must convert any non-string values to strings before you can store them in a cookie.
Upvotes: 1
Reputation: 3281
I found solution we can not store Datatable in Cookies but we can store DataTable in Cache.
Upvotes: 0