I know I am close with what I am doing but haven't found quite the right combination yet. I am a newbie so please bare with me!! I have a table called Dimension1Goal1 in a dataset called CCADPDataset that I am trying to pull the value of a field called Intervention1_1 out of to display on the screen. Her is what I have coded:
Dim DimGoalMethod As StringDimGoalMethod = CCADPDataSet._Dimension1_Goal1.Intervention1_1Column
I keep getting the error Value of type 'System.Data.DataColumn' cannot be converted to 'String'.
The properties of the field is a system.string, why can't I do this and what should I do
HELP!!

Storing the value of a field from a table into a variable to be displayed on the screen
REspawn
I dont have VS installed on this comp so i cannot tell you the exact syntax but you need to get the item from the dataset,
try doing it by using CCADPDataSet._Dimension1_Goal1.rows([rownumber]).item(Intervention1_1Column)
GL
pippen
ChrisS-AllentownPA
jodv
Row Index
| | 1 | 2 | 3 | 4 | Column Index
| | test | apple | grey | odor |
| 1 | a | b | c | d |
| 2 | e | f | g | h |
I know its the ugliest looking table anyone has ever seen, anyways the row index and the column index are in red and that is what your referencing right now. Now the column Names are in blue those you can also reference instead, so instead of referencing column Index as Integer 3 you could reference Column Index As String grey. They would return the same.
Hope that helps some more ;)
*EDIT
oooh that table really got ugly when I posted it!!! Anyways you should still get the idea.
John Blight
LonelyPixel
I dont have your specific dataset but have created one manually which will have a table name and field name you specify and add a row to it (This would be done by retrieving the data from a database normally)
Then retrieve the value from the row and display it in a messagebox. This should give you an idea about the syntax.
Module Module1
Sub Main()
'//Create a dataset with a table and column names same
'// Your is probably populated from database
Dim CCADPDataSet As New DataSet
CCADPDataSet.Tables.Add("_Dimension1_Goal1")
CCADPDataSet.Tables("_Dimension1_Goal1").Columns.Add("Intervention1_1Column")
'//Populate a row in the datatable
CCADPDataSet.Tables("_Dimension1_Goal1").Rows.Add("Value In Field")
'//Retrieve the value from the row I just added
Dim DimGoalMethod As String = CCADPDataSet.Tables("_Dimension1_Goal1").Rows(0).Item("Intervention1_1Column").ToString
'//Display it
MsgBox(DimGoalMethod)
End Sub
End Module
Jeff Drummond
BaconTastesGood
To get the value from that column in the first row i think you use
DimGoalMethod = CCADPDataSet._Dimension1_Goal1.Intervention1_1Column.item(0)
HTH
AbdulMateen
You can refer to the items by index or name. Whichever is more suitable. Name is sometime more robust because people have a nack of adding items into SQL Statements which then causes the values to go haywire if your using the index numbers, although if your using the names they should stay the same.
ArcaArtem
Well, this is getting me a little closer but I need to understand more of wht you mean by using the "name" instead of the index. The name of my column that I want to pull the item from is Intervention1_1.
Just so that everyone that has been monitoring this blog I did get it to work using the row and item with the index numbers. Due to this I am understanding how the indexes work and I appreciate everyone's help. I am sure I will be back!!
I will be trying to figure out the name issue to so anymore explanation on that will be helpful.
Thanks Again
Juniorscone
Otherwise the code I use to grab cell data out of a datatable is as follows :
Dim DimGoalMethod As String
DimGoalMethod = dimension1goal1.Rows(RowIndex as Integer).Item(ColumnIndex as Integer).ToString
just gotta figure out what row and column the field(cell) intervention1_1 is in.
Just to maybe help not sure if this would work or not but I think to grab it from a dataset is done as follows:
DimGoalMethod = CCADPDataSet.Tables(TableIndex as Integer).Rows(RowIndex As Integer).Item(ColumnIndex as Integer).ToString
only catch is you have to know what the datatable Index number is, which should be 0 if its the first one loaded into the dataset, 1 if its the second etc. etc.
Anyways I hope that solves your problem or atleast gets you on the right track.