Trouble Creating Reference to Table in Dataset

Bernie

Well-known member
Joined
Aug 13, 2007
Messages
98
Programming Experience
3-5
It's getting late and I can't get the syntax right on this. I have a dataset defined in the IDE called ReportData. It has a single table called dtReport. I'd like to create a variable that references the table directly.

I have:
VB.NET:
Dim dsThisReportData As ReportData
Dim tbThisReportData As DataTable

VB.NET:
' instantiate the dataset ...
dsThisReportData = New ReportData
' create referenced to the table in the dataset ...
tbThisReportData = dsThisReportData.Tables("dtReport")

The problem is that tbThisReportData does not point to the table in dsThisReportData. For now I've worked around it by using the fully qualified name of the table of dsThisReportData.Tables("dtReport") but it would be nicer to be able to have the reference to the table working.

Can anyone see what I've got wrong here?

Thanks,
Bernie
 
Dim dsThisReportData As New ReportData
Dim dtThisReport As ReportData.dtReportDataTable = dsThisReportData.dtReport


Can I suggest that you DO NOT call your datatable "dtReport"

Drop the dt part, because type names shouldnt have a hungarian prefix. i.e. you do not write:
Dim s as strString
Dim b as btnButton


What you see in the dataset designer is a Type, not an instance of a variable. VB.NET then goes and unhelpfully blurs the distinction by making any dataset instances you drop on a form carry the same name as the type.
Personally, for everything I drop on a form, I rename it:

ReportsData -> _reportsData

_ means private member variable, and lowercase r is the correct naming convention for a variable

This way, when I see:

_reportsData.Whatever

I know that Whatever is a property of ym instance fo a dataset

And

ReportsData.Whatever

is a type/subtype (like ReportsData.ReportsDataTable)


-

try to avoid using the word "Data" in dataset or datatable names:
ReportsData.ReportsDataTable 'reports datatable, or reportsdata table ?? confusing, esp since the ds is also called ReportsData


-

In total, in your shoes i'd make my code:

Dim rds As New ReportingDS
Dim rddt As ReportingDS.ReportDefinitionDataTable = rds.ReportDefinition

Clearer?
 

Latest posts

Back
Top