您的位置:首页 > 其它

用好DataTable对象使脚本更加灵活

2016-02-03 20:33 295 查看
1.动态获取在DataTable中添加新列并赋值

DataTable.GlobalSheet.AddParameter "Column1","Value1"

DataTable.GlobalSheet.AddParameter "Column2","Value2"

DataTable.LocalSheet.AddParameter "Column3","Value3"

DataTable.LocalSheet.AddParameter "Column4","Value4"

DataTable.GlobalSheet.AddParameter "Column5","Value5"

DataTable.LocalSheet.AddParameter "Column6","Value6"

DataTable.LocalSheet.AddParameter "Column7","Value7"

2.动态地在DataTable中增加新行并赋值

DataTable.GetSheet("Action1").SetCurrentRow(2)

DataTable.Value("Column4","Action1")="Row2"

或者也可以是:

DataTable.Value(1,2)="Row1"

3.动态获取DataTable中指定列的值

GetValue1=DataTable("Column5","Global")

MsgBox GetValue1

DataTable.GetSheet("Action1").SetCurrentRow(1)

GetValue2=DataTable("Column6","Action1")

MsgBox GetValue2

如果有两个Action,分别是Action1和Action2,要想使它们在获取的时候保持读取的行数一致,可以使用下面两种方法:

方法1:直接定位Action2的行

DataTable.GetSheet("Action2").SetCurrentRow(2)

方法2:使用变量传递保持行数一致

CurrentRow=DataTable.GetSheet("Action1").GetCurrentRow

DataTable.GetSheet("Action2").SetCurrentRow(CurrentRow)

4.动态获取DataTable中指定行的值

getValueByRow=DataTable.GetSheet("Action1").GetParameter("Column7").ValueByRow(1)

MsgBox getValueByRow

5.动态获取DataTable中当前行和设置当前行

获取当前行:

CurrentRow=DataTable.GetSheet("Action1").GetCurrentRow

MsgBox CurrentRow

设置当前行:

DataTable.AddSheet("Action2")

DataTable.GetSheet("Action2").SetCurrentRow(5)

注意:增加Action2的列数跟行数的计算没有任何关系

DataTable.GetSheet("Action2").AddParameter "Column8","Value8"

CurrentRow2=DataTable.GetSheet("Action2").GetCurrentRow

MsgBox CurrentRow2

6.获取得到DataTable总行数的命令

AllRowCount=DataTable.GetSheet("Action1").GetRowCount

MsgBox AllRowCount

 

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  DataTable 参数化