Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting the field name and the field value of a row
Message
From
13/01/2007 03:42:39
 
 
To
13/01/2007 01:52:55
General information
Forum:
ASP.NET
Category:
Databases
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01185330
Message ID:
01185334
Views:
12
Assuming I have a row which is a record that I selected with *. Thus, all the fields of the tables have been selected. Now, I need to loop thru all the fields and get the field name and the value. Anyone could show me a small sample code for scanning that?

Michel,

Essentially, you can use the DataColumn object, like so...
DataTable dt = new DataTable();
dt.Columns.Add("name",typeof(String));
dt.Columns.Add("datehired", typeof(DateTime));
dt.Columns.Add("salary",typeof(Decimal));
dt.Columns.Add("active", typeof(Boolean));

dt.Rows.Add("Kevin Goff", new DateTime(2000, 1, 1), 100000, true);
dt.Rows.Add("John Doe", new DateTime(2001, 11, 11), 50000, false);

object odcvalue;
string cColumnName;

foreach (DataRow dr in dt.Rows)
    foreach (DataColumn dc in dt.Columns) {
        cColumnName = dc.ColumnName.ToString();
        odcvalue = dr[dc];
        // if you want to do something with the object, check the datatype of the column object and 
        // proceed accordingly 
    }
Let me know if that helps....
KG
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform