Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Comparing Data Row column values and string values
Message
De
10/07/2013 12:59:28
 
 
À
10/07/2013 12:55:41
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01578028
Message ID:
01578130
Vues:
40
>Maybe:
>
public static object GetDefault(Type t)
>        {
>            if (t.IsValueType)
>            {
>                return Activator.CreateInstance(t);
>            }
>            return null;
>        }
then:
var passedObject = SafeConvert(passedValue, GetDefault(columnType));
>
>
>
>>>Do you seem how can we replace Convert.ChangeType with SafeConvert in this code
>>>
>>>
>>> foreach (KeyValuePair<String, String> kvp in rowValues)
>>>         {
>>>            String passedValue = kvp.Value;
>>>            var columnValue = bookingRow[kvp.Key];
>>>            Type columnType = ((DataColumn)bookingRow[kvp.Key]).DataType;
>>>
>>>            var passedObject = Convert.ChangeType(passedValue, columnType);
>>>            if (passedObject.Equals(columnValue) == false)
>>>            {
>>>               String cColumnValue = columnValue.ToString().Trim();
>>>               if (cColumnValue!=passedValue) // Double check to prevent cases of "" vs. "          "
>>>                  this.SaveToBookingHistory(booking_id, "M", kvp.Key, cColumnValue, passedValue, ref messageText, ref statusCode);
>>>            }
>>>         }
>>
>>
>>See my other answer

I may be wrong, but I think that results in the equivalent of
var passedObject = SafeConvert<object>(passedValue, GetDefault(columnType));
so passedValue would be boxed as an object instead of converted to the appropriate type, and the comparison would still fail.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform