将ds.Tables [1] .Rows [0] .ToString()转换为int

时间:2009-11-09 15:28:11

标签: c#

我无法将ds.Tables[1].Rows[0].ToString()转换为int。

ds.Tables[1].Rows[0] = 100; 

给出错误无法转换。

3 个答案:

答案 0 :(得分:3)

string test = Convert.Int32(ds.Tables[0].Rows[0]["YourIntegerColumn"].ToString())

如果你的列不是整数,那么它就不会起作用,所以你很可能想检查列是否为null,然后使用Int.TryParse

检查它是否可解析为int

答案 1 :(得分:3)

ds.Tables [1] .Rows [0]返回一个DataRow。您需要指明要为其分配值的列:

ds.Tables[1].Rows[0]["Your column name"] = value;

答案 2 :(得分:1)

你错过了这个专栏吗? ds.Tables [1] .Rows [0] [column] = value;