Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Check the field exist in myReader
Message
De
20/12/2007 09:40:03
 
 
À
19/12/2007 21:52:29
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01276746
Message ID:
01276806
Vues:
19
Agnes,

Well, with DataTables, there is a Columns collection that has a Contains() method, so that you can query if a column by that name exists. Apparently there is no Contains() method in the DataReader. You could, however, create your own method do to this.

Off the top of my head (don't have VS up at the moment):
public bool Contains(string ColumnName)
    for (int i=0; i < myReader.FieldCount; i++)
    {
        if (myReader.GetName[i] == ColumnName)
            return true;
    }
    return false;
}
And of course you'd use it like this:
if (this.Contains("kcno"))
    pKcno = myReader.Item("kcno");
~~Bonnie



>pKcno = myReader.Item("kcno") <--it will return error when the field "kcno" doesn't exist
>
>any method to check the field exist or not first , if not exist, I want to skip the above statement.
>
>Thanks
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform