Solved

C# Database Row

Posted on 2012-03-09
4
316 Views
Last Modified: 2012-03-12
Can anyone please explain me what does the myRow in ds.Tables["wc"] does in this code. For now I don't care if compiles or not. I just need to understand the its functionality.

foreach (DataRow myRow in ds.Tables["wc"].Rows)
	{

		if (myRow[4].ToString() == string.Empty)
		{

			sr.WriteLine(string.Concat(new object[] { 
				"'", myRow[0], "','", myRow[1], "','", myRow[2], "',", string.Empty, ",'", myRow[4], "','", myRow[5], "',", string.Empty, ",'", myRow[7], 
				"',", myRow[8], ",'", myRow[9], "'"
						//}
							}));

Open in new window

0
Comment
Question by:pauledwardian
  • 2
  • 2
4 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 500 total points
ID: 37703935
myRow is an iterator variable for the foreach loop. It represents each DataRow (it's corresponding type) found within the DataTable it is iterating over. In this case, the DataTable is housed within a DataSet. This DataSet is pointed to by the variable ds. Within the DataSet's Tables collection, you are getting to the "wc" table by indexing that property using the string "wc". (The square brackets represent C#'s index operator.) The table that is returned by that indexing operation has its Rows property iterated over using the aforementioned iterator variable.
0
 

Author Comment

by:pauledwardian
ID: 37705592
So WC is the table name?
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 37706165
As it exists within the DataSet, yes. It could have been loaded from any number of database tables with arbitrary names, or it could have been loaded from a file, or entered by the user, etc. But with respect to the DataSet, the DataTable was given the name "wc".
0
 

Author Closing Comment

by:pauledwardian
ID: 37712199
Thanks!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now