Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!!
Posted
Comments
[no name] 2-Feb-13 2:57am    
Try without using ''

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!!
 
Share this answer
 
Comments
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...?
to retrieve columns value through its name use
C#
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900