Question : Retrieve Data frm Session Datatable

I created a data table which I then stored in a session. Then later in my App I get it again but when I call it I only get the name of the Column not the Value.
I have included some of my code

Any help is Greatly Appreciated
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
In my Page load I have
If Page. isnotpostback then
Cmd.Connection = conn
Cmd.CommandText = "Get_Data"
cmd.CommandType = CommandType.StoredProcedure
SqlAdp.SelectCommand = cmd
SqlConn.open
SqlAdp.Fill(DTData)
Sqlconn.Close
Session("Data") =DTData
 
 
Then later on a button click I have
Dim dr as DataRow
Dim table as DataTable = CType(Session("Data"), DataTable)
For each row in Table.rows
Dim strCol1 as String = table.Columns.Item(0).toString
Dim strCol2 as String = table.Columns.Item(1).Tostring

Answer : Retrieve Data frm Session Datatable

Hello niall29,

For Each dr As DataRow In table.Rows
  Column1Value = dr.Item(0).ToString()
  Column2Value = dr.Item(1).ToString()
Next

You are only asking for the name of the column, it is the row's .Item property that you need which you are not actually trying to retrieve in this example. The above example should help you get what you want.

Regards,

TimCottee
Random Solutions  
 
programming4us programming4us