Solved

C# Database Row

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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!
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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