.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sharon Maxwell

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

To get a datarow from a datatable

Posted By: Chandranshu Awasthi     Posted Date: February 16, 2011    Points:2   Category :C#
i want to do something like
to get row number n

Author: shankey             
Posted Date: February 17, 2011     Points: 5   


try following
//Creation of static datatable
DataTable dt = new DataTable();
dt.Columns.Add("UserName", typeof(string));
dt.Columns.Add("IsMale", typeof(bool));
dt.Columns.Add("IsActive", typeof(Boolean));

dt.Rows.Add("Dharmedra", "true", "true");
dt.Rows.Add("Katrina", "false", "true");
dt.Rows.Add("Sunny", "true", "false");
dt.Rows.Add("Baba ramdev", "true", "true");
dt.Rows.Add("Sanjay dutt", "true", "false");
dt.Rows.Add("Kareena kapoor", "false", "false");

DataRow dr = dt.Rows[0]; // fetching first row
string str = Convert.ToString(dr[0]); // getting first column value of the fetched row

str will have "Dharmedra"


Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend