VB.Net到C#转换DataRow的问题

编程入门 行业动态 更新时间:2024-10-26 11:25:18
本文介绍了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的问题

本文发布于:2023-05-27 23:12:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/306124.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:VB   Net   DataRow

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!