Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Handle Nulls In DataSet
Message
De
23/02/2009 13:29:52
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01383505
Message ID:
01383540
Vues:
28
>I have a a dataset with bank register data in it. I am adding a column, and I want to loop through the DS and compute the balance on the fly. I have:
>
>
>
>oRegisterDS = csRegister.oDataProcs.ExecuteQuery("b_GetRegisters", "Register", oRegParams);
>
>DataColumn oBalanceCol = new DataColumn("Balance", System.Type.GetType("System.Double"));
>oRegisterDS.Tables["Register"].Columns.Add(oBalanceCol);
>
>double dBalance = 0;
>foreach (DataRow oRow in oRegisterDS.Tables["Register"].Rows)
>{
>    if (oRow["Payment"] == null)
>    {
>        dBalance = dBalance + Convert.ToDouble(oRow["Deposit"]);
>    }
>    else
>    {
>        dBalance = dBalance - Convert.ToDouble(oRow["Payment"]);
>    }
>
>    oRow["Balance"] = dBalance;
>}
>
>
>
>The value of the Payment column on row 0 is null, yet it skips down into the ELSE section. What's the correct way to work with NULL in a DS?
>
>Thanks

I haven't worked with DataSets in a few years... is there still a "IsXFieldNull" property? Also, is there a way to create a calculated field in a DataSet? IIRC it seems I ran into the same issue where I wanted to create a calculated field and didn't want to loop throught the DataTable to do that. I believe I couldn't find an easy way and that led me to the decision to use custom classes instead of DataSets.
Very fitting: http://xkcd.com/386/
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform