[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

access datarow  from a dataset

Posted on 2009-04-27
3
Medium Priority
?
558 Views
Last Modified: 2013-12-17
HI, I am a novice on datasets and would like to know how to acces the columns and each row clearly for teh dataset created by me. Please help

The dataset is ds_tablespecs

foreach (DataTable dt in ds_tablespecs.Tables)
            {
                foreach (DataRow dr in dt.Rows)
                {
 
                    foreach (DataColumn dc in dt.Columns)
                    {
I nee d to access each datarow here 
 
 
                    }
                 }
        }

Open in new window

0
Comment
Question by:aspgeek
  • 2
3 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 24240150
See also http://authors.aspalliance.com/aspxtreme/adonet/adonetprimer.aspx?pageno=8
foreach ( DataTable table in myData.Tables ) {
   foreach ( DataRow row in table.Rows ) {
      foreach ( DataColumn col in table.Columns ) {
         Response.Write ( row [ col ].ToString ( ) );
      }
   }
}
 
foreach table as DataTable in myData.Tables
   foreach row as DataRow in table.Rows
      foreach col as DataColumn in table.Columns
         Response.Write ( row ( col ).ToString ( ) ) 
      next
   next
next

Open in new window

0
 

Author Comment

by:aspgeek
ID: 24240507
Thanks for the response. I need to actually access it as datarows. How do i do it. I know we need to use datarows but I am having some trouble doing it
  foreach (DataTable table in ds_tablespecs.Tables)
                    {
                        foreach (DataRow row in table.Rows)
                        {                          
                               // Response.Write(row[col].ToString());
                                Label label1 = new Label();

                      label1.Text = ds_tablespecs.Tables[0].Rows[0]["COLUMN_NAME"].ToString();
                       }
                    }


I need to keep iterating the row as in to  the next one
ds_tablespecs.Tables[0].Rows[row]["COLUMN_NAME"].ToString();

instead of just having it as
ds_tablespecs.Tables[0].Rows[0]["COLUMN_NAME"].ToString();

I get two errors while trying to do this
The best overloaded match system.data.datarowcollection[int] has invalid arguments.
and
Argument 1 cannot convert from string to int

Please help
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 24240627
foreach (DataTable table in ds_tablespecs.Tables)
                    {
                        foreach (DataRow row in table.Rows)
                        {                          
                               // Response.Write(row[col].ToString());
                                Label label1 = new Label();

                      label1.Text = row["COLUMN_NAME"].ToString();
                       }
                    }
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question