Reputation: 63
So I have a DataTable which uses:
SELECT * FROM People WHERE ID = ?
You can understand that this will only retrieve one row as the ID is unique:
usersTableAdapters.UsersTableAdapter user = new usersTableAdapters.UsersTableAdapter();
users.UsersDataTable userDataTable = user.getUserInfo(id);
I have then stored the DataTable into a session:
HttpContext.Current.Session.Add("userDT", userDataTable);
Now I am trying to figure out, how would I get a specific column from the userDT in the session? To be more clear the firstname column?
Upvotes: 0
Views: 1622
Reputation: 13599
Try this,
DataView dv = new DataView((DataTable)HttpContext.Current.Session["userDT"]);
get the table just with column
DataTable dt = dv.ToTable(true, "firstName");
Upvotes: -1
Reputation: 131
You have to cast Session object to users.UsersDataTable: users.UsersDataTable userDataTable = Session["userDT"] as users.UsersDataTable;
Upvotes: 1
Reputation: 15875
First cast the session object as a datatable.
var tbl = ((DataTable)HttpContext.Current.Session["userDT"])
Then use it like a data table:
var col = tbl.Columns["firstName"];
Upvotes: 1