DataSet.Tables[0].Rows[0][1] !=DataSet.Tables[0].Rows[0].ItemArray[1] ??
DataSet.Tables[0].Rows[0][1]=Convert.ToInt32(DataSet.Tables[0].Rows[0][1])+1;
可以对XML文件中的相关数据进行加一操作,但下面的却不可以:
DataSet.Tables[0].Rows[0].ItemArray[2]=Convert.ToInt32(DataSet.Tables[0].Rows[0].ItemArray[1])+1;
DataSet.Tables[0].Rows[0][1]是指DataSet中的表0,行0,列1
DataSet.Tables[0].Rows[0].ItemArray[1]不是指DataSet中的表0,行0,列1吗?
这两个有什么不同???
为什么下面的不能执行加一操作???
问题点数:20、回复次数:6Top
1 楼saucer(思归)回复于 2004-08-02 08:06:18 得分 15
DataSet.Tables[0].Rows[0][1] should be equivalent to DataSet.Tables[0].Rows[0].ItemArray[1]
what error did you get? what is the data type in DataSet.Tables[0].Rows[0].ItemArray[2]?
Top
2 楼triout(笨牛)回复于 2004-08-02 08:34:08 得分 5
死鬼大哥给你答案了,还没有明白?
DataSet.Tables[0].Rows[0][1]
DataSet.Tables[0].Rows[0].ItemArray[1]
DataSet.Tables[0].Rows[0].Columns[1]
都是一样的,所以你的操作应该是正确的。
但你的操作出现了错误,为什么?你没有说出报告的错误内容。
但从你的代码来看,是因为DataSet.Tables[0].Rows[0].ItemArray[2]的原因。
想问,2号元素从哪里来的?
DataSet.Tables[0].Rows[0][1]=Convert.ToInt32(DataSet.Tables[0].Rows[0][1])+1;
对应为
DataSet.Tables[0].Rows[0].ItemArray[1]=Convert.ToInt32(DataSet.Tables[0].Rows[0].ItemArray[1])+1;
Top
3 楼zedan(kk)回复于 2004-08-02 11:13:35 得分 0
ItemArray[2]只是一时写错而已。
(DataSet.Tables[0].Rows[0].ItemArray[0])=Convert.ToInt32(DataSet.Tables[0].Rows[0].ItemArray[0])+1;
执行后查看XML文件发现并没加一,而改为
(DataSet.Tables[0].Rows[0][0])=Convert.ToInt32(DataSet.Tables[0].Rows[0][0])+1;
执行后查看XML文件发现有加一!!
很奇怪Top
4 楼saucer(思归)回复于 2004-08-02 21:51:14 得分 0
they are different when they are lvalue, DataSet.Tables[0].Rows[0].ItemArray returns an array of values, if you assign some value to an element, you are just assigning to the array, not to the Rows[0]
you can do
Rows[0].ItemArray = new object[]{value1, value2, value3};//...Top
5 楼zedan(kk)回复于 2004-08-03 13:32:10 得分 0
但ItemArray[0]不是指一组中的第一个字段吗??
输出DataSet.Tables[0].Rows[0].ItemArray[0]确是第一个字段的值啊。?Top
6 楼saucer(思归)回复于 2004-08-03 20:29:17 得分 0
read the documentation carefully:
DataRow.ItemArray Property
Gets or sets all of the values for this row through an array.
Top




