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


Top 5 Contributors of the Month
david stephan

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
datarow=Datatable.rows(n)
to get row number n

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

hi,

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"

Shankey


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
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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