Subscribe to Subscribers
Talk to Webmaster Tony John

Forums » .NET » ASP.NET »

how to get value of cell of datatable in c#


Posted Date: 28 May 2008      Posted By:: Red Swan     Member Level: Gold    Member Rank: 624     Points: 1   Responses: 5



how to get value of cell of datatable in c#:
I need to get the value from datatable from eachrow in single row...how it is?




Responses

#238583    Author: Ashok Kandasamy      Member Level: Gold      Member Rank: 242     Date: 28/May/2008   Rating: 2 out of 52 out of 5     Points: 2

hi,
Try this,

DataTable dt = new DataTable();
string rowValue = dt.Rows[0].ToString();
string coloumnValue = dt.Columns[0].ToString();



 
#238584    Author: Sujit Kumar      Member Level: Gold      Member Rank: 225     Date: 28/May/2008   Rating: 2 out of 52 out of 5     Points: 2

datatable.Rows[0][0]

//Rows[0][0], first[0] means rows and second [0] means column

Regards,
Sujit Kumar
DotNet Blogs



 
#238588    Author: kavithiagu      Member Level: Silver      Member Rank: 0     Date: 28/May/2008   Rating: 2 out of 52 out of 5     Points: 2

try it

if (ds1.Tables.Count > 0)
{
for (int j = 0; j < ds1.Tables[0].Rows.Count; j++)
{
DataRow odr = ds1.Tables[0].Rows[j];

dataGridView1.Rows.Add();
dataGridView1.Rows[j].Cells[1].Value = odr["columnname"].ToString();
dataGridView1.Rows[j].Cells[2].Value = odr["columnname"].ToString();
dataGridView1.Rows[j].Cells[4].Value = odr["columnname"].ToString();
dataGridView1.Rows[j].Cells[2].ReadOnly = true;
dataGridView1.Rows[j].Cells[4].ReadOnly = true;

}






 
#238589    Author: Siva Prasad      Member Level: Gold      Member Rank: 1476     Date: 28/May/2008   Rating: 2 out of 52 out of 5     Points: 2

Hello Lalit,

string cellValue = dataTable.Rows[0][1].ToString();

Siva Prasad



 
#238752    Author: Parashu(Swathimutyam)      Member Level: Gold      Member Rank: 0     Date: 28/May/2008   Rating: 2 out of 52 out of 5     Points: 2

for (int i = 0; i < ds.Tables["reg_table"].Rows.Count; i++)
{
for (int j = 0; j < ds.Tables["reg_table"].Columns.Count; j++)
{
items.Add(ds.Tables["reg_table"].Rows[i][j].ToString());
}
}

the above code will retrive a first row and all the columns,
based on this idea please implement your code

Regards,
Parshu(Swathimutyam)



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : cookies problem
Previous : Paging in Datagrid
Return to Discussion Forum
Post New Message
Category:

Related Messages
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.