Solved

C# Database Row

Posted on 2012-03-09
4
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

691 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