how to Replace null value with 0 Using C#

how to Replace null value with 0 Using C#



//here we suppose that objDataTable have data collection as table now access this //datatable object.

decimal j = 0;

 j = objDataTable.Rows[0]["Qty"] == DBNull.Value ? 0 : Convert.ToDecimal(objDataTable.Rows[0]["Qty"]);




NOTE :-
//if  DBNull.value is null then  "0 " else  "your code here") 
// ? = then
// : = else




Thank You
[Sumit Singh Shekhawat]

Comments

  1. select Isnull(Qty,0) As Qty from Table

    ReplyDelete
  2. Thanks for showing your smartness, but i'm showing example for only in C#.

    ReplyDelete

Post a Comment

Popular posts from this blog

Tree view in winforms using c#

how to fetch all HTML Table Records and modify all records accordingly using jquery and Javascript