Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to avoid decimal value not null becoming nullable on assigning to an object? I am having the value in the dataset but its becoming nullable on assigning to object with fieldname. How to avoid the issue.
Posted
Comments
Gitanjali Singh 29-Jan-14 6:34am    
Please post your code.
King Fisher 29-Jan-14 6:46am    
show your Query which you binding with the dataset

Use which one suits for your issue..

C#
decimal value = default(decimal); //0
        object objvalue = value; // object will be having 0

        decimal? nullableValue = null;  // null
        object objval = nullableValue.HasValue ? nullableValue.Value : default(decimal);

        decimal val = default(decimal);  //0
        decimal.TryParse(DBNull.Value.ToString(), out val); // if null it will be assigned as 0 , else the value
        object valueFromDataset = val;
 
Share this answer
 
Comments
JoCodes 29-Jan-14 7:00am    
Nice one Karthik. my 5
Karthik_Mahalingam 29-Jan-14 7:19am    
Thanks JoCodes:)
A decimal will always have some default value. If you need to have a nullable type[^] decimal, you can use decimal?. Then you can do myDecimal.HasValue
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900