473,614 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to loop through DataRow[] to get the column name and value

11 New Member
Hi
I have a DataTable and get selected values out of it in a DataRow collection. I have the code that I want to make it run. Not sure if this is the correct approach to store column names and value in memory for later use?
Expand|Select|Wrap|Line Numbers
  1. DataTable dt = ds.Tables["Employee"];
  2. DataRow[] foundEmpRows = dt.Select("Dept = 10");
  3.  
  4. NameValueCollection nvEmp = new NameValueCollection();
  5. foreach (DataRow dr in foundEmpRows)
  6. {
  7.   foreach (DataColumn dc in foundEmpRows)
  8.   {
  9.     nvEmp.Add(dc.ColumnName, dr[dc]);
  10.   }
  11. }                            
  12.  
The statement in BOLD is giving error. How to access DataColumn from DataRow[] array?
Sep 24 '10 #1
1 48111
Sri13
11 New Member
I was able to resolve it myself :)
I updated the inner loop to:
Expand|Select|Wrap|Line Numbers
  1. foreach (DataColumn dc in dr.Table.Columns) 
  2.   nvEmp.Add(dc.ColumnName.ToString(), dr[dc].ToString()); 
  3. }
  4.  
Sep 24 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2299
by: ibm_97 | last post by:
DB2 8.2 on AIX Hi, I'd like to change a column's name in a table which is part of replication. This column is identity column (generated always). 1. Since DB2 will drop and recreate the table with the changed column name, do I have to do something like 'set integrity off'?
10
6556
by: Colleyville Alan | last post by:
I am trying to turn a short and fat (63 columns) table into one that is tall and skinny (7 columns). Basically, I am trying to create a "reverse crosstab" using a looping structure in VBA along with SQL. I'd like to take the name of the column and input it into a descritor field. This isn't the table, but will serve as a better illustration than the real deal. If the table looks like this:
4
1925
by: JIM.H. | last post by:
Hello, string colVal =((TextBox)e.Item.Cells.Controls).Text; this is how I reach column value in a grid: how can I reach with the column name? some value should be int, some date, how should I read them? Thanks, Jim.
7
2568
by: RSH | last post by:
I need to use a form element to display a list of users. I would like to store their ID "behind the scenes" so when the user selects a name the Event passes their ID. I can't find anything about how to set a Name/Value pair of a ComboList. Is this the wrong tool for the job? Or how do I set the two values? Thanks so much, Ron
2
1731
by: RSH | last post by:
Hi, i have a situation where I have an object (Company) that returns a dataset for the Employees Property which in turn I would like to bind to a DDL. My problem is that I want to be able to select the Employee from the DDL and return the detail information for the selected employee onSelectIndexChanged. I was thinking since I alredy have the information in the Object I would like to bind the datarow to the value and onchange I would...
1
2815
by: orenl | last post by:
I have a DataRow (from DataTable) and i want to get data from a column name that might not exist. public static object getObject(DataTable dataTable, int index, string columnName) { return dataTable.Rows; }
3
1921
by: Jeff | last post by:
In .net2 using VB (Visual Web), I have the following code that properly determines the column name from the column number (5 in this example) from a single row table. ColName = tempA.Table.Columns(5).ColumnName() I can't figure out the code to return the column number if I have the column name. E.g., something like this:
1
1356
by: bbawa1 | last post by:
Hi, I have a grid view I am trying to invisible the fifth column. The rows are now not showing any data in column but the column name is still showing. I want to make invisible column name also. if (e.Row.RowType == DataControlRowType.DataRow ) { e.Row.Cells.Visible = false; }
1
2316
by: Big Moxy | last post by:
Problem URL - http://projects.zanalysts.com/ariviewer/display.asp?ID=11 I'm using Access as the "database". I get this error in the above URL: ADODB.Fields error '800a0cc1' Item cannot be found in the collection corresponding to the requested name or ordinal. /ariviewer/display.asp, line 498
0
2712
by: Sebastijan | last post by:
Hi I am interested in DbConnection.GetSchema method of ODP.NET oracle library. When I call (to get primary keys metadata) DataTable pkeys = DbConnection.GetSchema("PrimaryKeys"... foreach (DataRow dr in pkeys.Rows) { string pkTable = dr.ToString();
0
8197
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8142
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8287
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6093
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4136
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2573
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1438
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.