Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Iterate over columns in LINQ to SQL result
Message
De
18/11/2008 10:32:43
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01362512
Message ID:
01362551
Vues:
9
>To All:
>
>I have the following code:
>
>
>var _CSVTests = from cs in db.CSVTests
>                         select cs;
>
>foreach (CSVTest tst in _CSVTests)
>	{
>		
>		 In here I want to iterate over each column in each record and 
>		 if it is not equal to NULL I want to do something with the value,
>		 such as insert that value into another table.
>		
>	}
>
>
>How do I access the properties and values of each column in the results of my _CSVTests? Do I use IQueryable instead of var? How will that help me? I've been searching for this answer for two days now. PLEASE HELP.
>
>Thank you.

You could do something like this:
    var fields = typeof(CSVTest).GetProperties();
    foreach (CSVTest tst in _CSVTests)
    {
          foreach (var field in fields)
          {
              object v = field.GetValue(tst, null);
              if ( v == null ) 
                // ...
         }
    }
Maybe copying to a datatable would be easier. Check ObjectShredder< T >:
http://msdn2.microsoft.com/library/bb669096.aspx

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform