Click here to Skip to main content
13,050,840 members (58,083 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi... I am using a dataset and to retrieve a particular column value usual synatx is like


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!!
Posted 1-Feb-13 20:51pm
Krunal Rohit 2-Feb-13 2:57am
Try without using ''
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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!!
Shruthi.BT 2-Feb-13 4:18am
thank u .. Mantu Singh .... this worked using index... if in case there is a row.. which is blank for ex...

ds.Tables[0].Rows[0][0].ToString() == ""

then i need to delete that.. row. how can that be done.. as i want the null values from dataset to be removed from the dattaset...

please help!!
Mantu Singh 2-Feb-13 4:24am
To delete you can use
ds.Tables[0].Rows[0].Delete(); //delete first row
ds.Tables[0].Rows[1].Delete(); //delete second row
Shruthi.BT 2-Feb-13 5:37am
but this line not working shows error.... as

'object' does not contain a definition for 'Delete'
is there any other way to delete...?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100