473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Storing session in array

6
Hello ..I am new to asp.net .I have this problem of storing session values in a variable as an array.That is ..an array should contain the session values.How am i to do this in C#?and how can I retrieve them as well?

Thanks in advance!
Sep 3 '07 #1
3 1689
Shashi Sadasivan
1,435 Expert 1GB
Hello ..I am new to asp.net .I have this problem of storing session values in a variable as an array.That is ..an array should contain the session values.How am i to do this in C#?and how can I retrieve them as well?

Thanks in advance!
Could you please define the structure of your variable / class ?
Sep 3 '07 #2
Astha
6
Hey ,thanks ...this is my piece of code..


uname = Session["sessionname"].ToString();

taskcd = new string[10];

viewable = new string[10];

editable = new string[10];

deletable = new string[10];

addable = new string[10];

string sql = "select view_flag,edit_flag,delete_flag,add_flag,task_cd from Task_user where name='" + uname + "' ";

cmd = new SqlCommand(sql, co.oConn);
rd = cmd.ExecuteReader();

while (rd.Read())
{

taskcd[i] = rd["task_cd"].ToString();
Session.Add("taskcode", taskcd[i]);

viewable[i] = rd["view_flag"].ToString();
Session.Add("viewable", viewable[i]);

editable[i] = rd["edit_flag"].ToString();
Session.Add("editable", editable[i]);


deletable[i] = rd["delete_flag"].ToString();
Session.Add("deletable", deletable[i]);


addable[i] = rd["add_flag"].ToString();
Session.Add("addable", addable[i]);

i = i + 1;
}

rd.Close();



this is the way I have been adding the session values to the array.But there must be some other better methods.Here,there are 6 task codes for 1 user.Each task code has all the view,add,delete and edit flags.What I am supposed to do is redirect the user to the page(or task),according to the privilege he has.Like some might have only previlige to view and not to edit,delete or add and so on.So,the main problem is to find this out and to redirect to the correct page.pls help.

Thanks!
Sep 3 '07 #3
Shashi Sadasivan
1,435 Expert 1GB
Hi
If i were you and was to stick to keeping all the code as strings
i wud create a class and put the username, along with the 6 different values in it.
If you want to club up all the strings as one object, its good to use ahash table or a dictionary to do it.

Expand|Select|Wrap|Line Numbers
  1. public class userSession
  2. {
  3.    public string uname;
  4.    public Dictionary<string, string> perms;
  5. }
hope you do know how to use Dictionary....there is lots of help already available if you may google.

but looking at what you need, u might keep those 6 flags as booleans in the class i created above instead of a dictionary.

Once u create an object of the class....store it into ure Session.

cheers
Sep 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Francisco | last post by:
I have this problem: I have a database with information about games, and users are able to vote for them. Everytime a user votes for a game I store the unique game name into a session variable (an...
4
by: mechweb | last post by:
Hi all, I can successfully store an array in a session variable like so: string arr1 = new string; Session = arr1; But, when I try to display the elements (using the code below) on another...
2
by: jakk | last post by:
Below is the exception that Iam getting. It says that the DataView that Iam storing in the session is not Serializable. BUt works fine if I store in the inproc session and fails if I switch to...
3
by: Brad | last post by:
I am storing an array which contains about a dozen chracter items to a Session variable. Later, I need to use this array so I am doing the following: Dim eventTypes As String() =...
10
by: Mark Rae | last post by:
Hi, This relates to the previous thread "Disappearing Sessions", but is a bit more generic so I thought I'd start a new thread. This one relates to the storing of objects in Session once only to...
0
by: toton | last post by:
Hi, I have a little design related problem, and finding a good way to resolve it. To state the problem, I have points from writing of several documents. Each document represents a Session class ,...
1
by: None | last post by:
Hi, I have developed webshop application using asp.net 1.1. I'm using DataGrid in one of the pages of my site. During the page load the DataGrid will be binded by around 7500 products(rows). At...
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
6
by: J055 | last post by:
Hi I have the following code. I upload an XML file using the FileUpload object, store the stream in a session so the user gets the chance to confirm some options then pass the stream from the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.