开发者

How to read column value generically from a datatable in .NET without explicitly specifying the data type and column name

开发者 https://www.devze.com 2023-02-24 09:02 出处:网络
I want to read column value from a datatable without explicitly specifying the data type and column name.

I want to read column value from a datatable without explicitly specifying the data type and column name.

E.g.

int carId = CarTable.Rows[i].Field<int>("CarId");  //this requires the开发者_如何学JAVA data type and column name.

string name= CarTable.Rows[i].Field<string>("Name"); 

I want to read to carId without explicitly specifying the data type and column name.

Will it be easier if I want the return type of all columns be string type?


Assuming you're thinking of using the column's position rather than its name, you should be able to do :

Object colvalue = CarTable.Rows[i].Items[colpos];
0

精彩评论

暂无评论...
验证码 换一张
取 消