动态检索数据集中特定列的值 [英] dynamiacally retrieving values of particular column in dataset
问题描述
嗨......我正在使用数据集并检索特定的列值,通常的synatx就像是
ds.Tables [0 ] .Rows [j] [Name]。ToString
但我的列名是动态获取意味着它可以是名称,动物,地方等,但这是完全动态的而不是静态的,所以如何在该数据集行中传递该值...我试着这样:
i按名称获取变量中的动态列名称,如下所示:
string ColumnNames;
ds.Tables [0] .Rows [j] [''+ ColumnNames + ''] .ToString
所以如何在该行中传递这个动态列名...我在哪里检查一个特定的字符串...提前告诉你!!
在这种情况下你可以使用像下面这样的索引,你不需要名字:
ds.Tables [0] .Rows [0] [0] .ToString(); //第一行第一列
ds.Tables [0] .Rows [1] [2] .ToString(); //第二行第三列(索引开始0)
好运!!
通过名称使用来检索列值
string ColumnName = < span class =code-string> myColumnsName;
string columnsValue = ds.Tables [ 0 ]。行[j] [ColumnName]。的ToString();或
string columnsValue = ds.Tables [ 0 ]。行[j] [ColumnIndex] .ToString(); // ColumnIndex是代表你的专栏的数字
Hi... I am using a dataset and to retrieve a particular column value usual synatx is like
ds.Tables[0].Rows[j]["Name"].ToString
but the column name i am getting dynamically means it can be name, animal, place etc but that is completely dynamic not static so how to pass that value in that dataset line... i tried like this:
i get the dymacic column names in a variable by name like this:
string ColumnNames ;
ds.Tables[0].Rows[j][''+ ColumnNames +''].ToString
so how can i pass this dynamic column name in that line... where i am checking a particular string... THanking you in advance!!
You can use index like arrays as below you wont need name in that case:
ds.Tables[0].Rows[0][0].ToString(); //first row first column ds.Tables[0].Rows[1][2].ToString(); //second row third column(index start 0)
Best of luck!!
to retrieve columns value through its name use
string ColumnName = "myColumnsName"; string columnsValue = ds.Tables[0].Rows[j][ColumnName].ToString(); or string columnsValue = ds.Tables[0].Rows[j][ColumnIndex].ToString();//ColumnIndex is a number representing your column
这篇关于动态检索数据集中特定列的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!