Click here to Skip to main content
15,896,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
forgive me if it is a very silly question

i access Cell of DataTable like this

string value=dataTable.rows[0]["DataColumnName"].ToString();

but it only return that column name not value of the cell

what's wrong?

help me. thank u
Posted
Comments
joshrduncan2012 11-Jul-13 11:51am    
I think you are missing ".Value" before ".ToString()".
deva936 11-Jul-13 12:00pm    
it don't have .Value property
i have tried it
joshrduncan2012 11-Jul-13 12:03pm    
My mistake. I glanced at the code you provided and assumed you were referencing a datagridview cell instead of a datatable cell.

I think you might be missing ".ItemArray[ColumnIndex]" where "columnindex" is the position of the column.
[no name] 11-Jul-13 12:08pm    
http://msdn.microsoft.com/en-us/library/146h6tk5.aspx

1 solution

Debugg code and Before initialization Check in Quick Watch that what exactly value of datatable cell have.
C#
//it should work. 
string value=dataTable.rows[0]["DataColumnName"].ToString();
// but you can try this. hope so it'll work.
// there is nothing wrong with your code.
// 2 as column index
string value=dataTable.rows[0][2].ToString();
 
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