Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting VB to C# 1

Status
Not open for further replies.

stnkyminky

Programmer
Oct 15, 2001
476
US
VB
Dim dt1 as new DataTable
dt1 = ds.Tables(0)

C#
DataTable dt1 = new DataTable();
dt1 = ds.Tables(0); <--'System.Data.DataSet.Tables' denotes a 'property' where a 'method' was expected


I thought the code should be the same for either language.



Also here is what sparked the whole question. I have a crystal report that contains 1 subreport. I am pushing data to the report.

Here is my attempt in C#. I know for a fact that this will work in VB.net. BTW I get the same error as above with this code as well.

report.SetDataSource(ds.Tables(0));
report.OpenSubreport(&quot;kanban3&quot;).SetDataSource(ds.Tables(1));



Scott
Programmer Analyst
<{{><
 
In C#, parenthesis --> ()
are used for method calls. If you need to index into an array or collection, use square brackets --> []

In your case, the .Tables property returns a collection of tables, so you'd use the square brackets.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
A good practice is to use the table name instead of using its index to access a DataTable object in a Tables collection of a Dataset object e.g.
-when a DataTable is added to a DataSet set a name for it
-when a DataTable will be accessed then use its name like :
DataTable dt= ds.Tables[&quot;Customers&quot;] instead of
DataTaable dt = ds.Tables[1];

-obislavu-

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top