Click here to Skip to main content
16,016,712 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

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 :

VB
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
dbDataset.Tables(0).Rows.Add(r)



My attemt at a C# version looks like:

MIDL
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;
dbDataset.Tables(0).Rows.Add(r);



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.

Thanks.
Posted

This should help:

dbDataset.Tables[0]
 
Share this answer
 
Change Tables(0) to Tables[0]. VB uses () while C# uses [].
 
Share this answer
 
v2
Comments
WurmInfinity 8-Feb-11 10:03am    
Thank you so much :D
Nish Nishant 8-Feb-11 10:05am    
You're welcome.
Sergey Alexandrovich Kryukov 8-Feb-11 16:11pm    
Ha! Funny mistake. Take a 5.
--SA

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