Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting the field name and the field value of a row
Message
De
13/01/2007 03:42:39
 
 
À
13/01/2007 01:52:55
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01185330
Message ID:
01185334
Vues:
13
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform