question

JohnVKaneIII-0870 avatar image
0 Votes"
JohnVKaneIII-0870 asked XingyuZhao-MSFT commented

How to get Field Name in code

I am trying to get the Field Name that is on the Fields tab in Dataset Properties and can't figure out how. I need to get the field name so I can compare it to a list of values. I am sure a custom function could be created, I just don't know VB.

sql-server-reporting-servicesdotnet-visual-basic
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @JohnVKaneIII-0870 ,
Take a look at the following code and see if it is helpful to you.

         For Each dt As DataTable In DataSet1.Tables
             MessageBox.Show(dt.TableName)
         Next

If I have any misunderstanding, please let me know.

0 Votes 0 ·

@XingyuZhao-MSFT I might be able to change it around to make it work. What I really want to do is create a VB Function that accepts a field from a dataset and returns it's name in a string. Then I could call the function in a text box on a report or in a visibility condition.

Something like Code.GetFieldName(Fields!Number001) that will return "Number001".

0 Votes 0 ·
OlafHelper-2800 avatar image
0 Votes"
OlafHelper-2800 answered JohnVKaneIII-0870 commented

I am trying to get the Field Name that is on the Fields tab in Dataset Properties

Sorry, for me it's not clear what you mean, may can you explain it more detailed, please?
And for what/where do you need to know column names? Columns of a query are fix, so you should already know the names.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@OlafHelper-2800

The reason I need to get the field name is to then check it to see if it is contained in a list of values. I have one dataset that contains almost 1,000 columns that I need to hide/show based off of a delimited list that is returned in another dataset. I am limited by what I can output because the data is being produced from our ERP.

0 Votes 0 ·
XingyuZhao-MSFT avatar image
0 Votes"
XingyuZhao-MSFT answered XingyuZhao-MSFT commented

Hi @JohnVKaneIII-0870 ,
A dataset usually contains many datatables. If you accepts a datatable from a dataset, you can use DataTable.TableName to get the name directly.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I understand now. thanks.

0 Votes 0 ·

Hi @JohnVKaneIII-0870 ,
If the answer is helpful, please click "Accept Answer" and upvote it.

0 Votes 0 ·