Click here to Skip to main content
15,040,212 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

Basically i've been given this peice of code to convert from VB.Net to C#. I havent done any VB.Net before. So far i've managed to convert all the code but once peice and was wondering if anyone could help. This involves writing a new data row using OleDb.

The VB.Net code looks like :

Dim r As DataRow = dbDataset.Tables(0).NewRow()
r("UserName") = userName
r("Calculation_Date") = Date.Today()
r("Car_Kg") = carbonCar
r("Public_Transport_Kg") = carbonTransport
r("Plane_Kg") = carbonPlane
r("ATS_Kg") = carbonTotal

My attemt at a C# version looks like:

DataRow r = dbDataset.Tables(0).NewRow();
r["UserName"] = userName;
r["Calculation_Date"] = Date.Today();
r["Car_Kg"] = carbonCar;
r["Public_Transport_Kg"] = carbonTransport;
r["Plane_Kg"] = carbonPlane;
r["ATS_Kg"] = carbonTotal;

The error occurs with the Tables(0) context saying it cannot be used as a method. I've tried to find and answer but i've decided asking for help might work a little better.


Change Tables(0) to Tables[0]. VB uses () while C# uses [].
WurmInfinity 8-Feb-11 10:03am
Thank you so much :D
Nish Nishant 8-Feb-11 10:05am
You're welcome.
Ha! Funny mistake. Take a 5.
This should help:


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900