基本上,我已经获得了这段代码,可以将其从VB.Net转换为C#.我以前没有做过任何VB.Net.到目前为止,我设法转换了所有代码,但是一次转换了,并且想知道是否有人可以提供帮助.这涉及使用OleDb写入新的数据行. VB.Net代码如下所示:
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 dbDataset.Tables(0).Rows.Add(r)我在C#版本上的attemt如下:
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; dbDataset.Tables(0).Rows.Add(r);该错误发生在Tables(0)上下文中,表明它不能用作方法.我试图寻找并回答,但我决定寻求帮助可能会更好一些. 谢谢.
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.
推荐答案将Tables(0)更改为Tables[0]. VB使用(),而C#使用[]. Change Tables(0) to Tables[0]. VB uses () while C# uses [].
这应该有所帮助: dbDataset.Tables[0] This should help: dbDataset.Tables[0]
更多推荐
VB.Net到C#转换DataRow的问题
发布评论