的System.Data.DataRow C#错误 [英] System.Data.Datarow C# error
问题描述
所以我创造我的第一个C#系统的边缘。我用我的vb.net系统作为我自己参考使用
So I'm in the verge of creating my first C# system. I use my vb.net system to use as my reference.
这是我的vb.net系统上的代码:
This is the code on my vb.net system:
Dim value As Integer = Val(dt.Rows(0).Item("TransID"))
我不得不使用一个在线转换器,这是我得到了什么:
I had to use an online converter and this is what I got:
int value = double.Parse(dt.Rows[0].Item[TransID]);
我弯弯曲曲了线项下的 - 告诉我,
I got squiggly lines under "Item" - telling me that
错误的System.Data.DataRow'不包含定义'项目'
和没有扩展方法'项目'接受的类型
的第一个参数的System.Data.DataRow'可以找到(是否缺少使用
指令或程序集引用?)
Error System.Data.DataRow' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'System.Data.DataRow' could be found (are you missing a using directive or an assembly reference?)
可能是什么问题?
推荐答案
该行应该读
int value = double.Parse(dt.Rows[0]["TransID"].ToString());
dt.Rows [0]
返回第一行, dt.Rows [0] [TRANSID]
返回TRANSID列的值对象
从第一行。由于解析
只需要字符串,而不是对象,则需要的ToString()
以及
dt.Rows[0]
returns the first row, dt.Rows[0]["TransID"]
returns the value of the "TransID" column as object
from the first row. As Parse
only takes strings, not objects, you need ToString()
as well.
要避免的ToString
你也可以使用以下,这是更好的:
To avoid ToString
you could also use the following, which is even better:
int value = (int)Convert.ToDouble(dt.Rows[0]["TransID"]);
这篇关于的System.Data.DataRow C#错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!