VB.Net到C#转换DataRow的问题 [英] VB.Net to C# Conversion DataRow issue

查看:90
本文介绍了VB.Net到C#转换DataRow的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



基本上,我已经获得了这段代码,可以将其从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的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆