Solved

C# Database Row

Posted on 2012-03-09
4
308 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 74

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 74

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

11 Experts available now in Live!

Get 1:1 Help Now