Search code examples
c#castingshort

Short Casting Error in C#


I am trying to get short variables value from my database and need to cast it but it gives an casting error at debugging how can I solve this problem ?Can you help me?

    obj_OBJimagegallery.watermark =String.IsNullOrEmpty((dr["watermark"]).ToString()) ? null : (short?)(dr["watermark"]);      

Solution

  • I have solved my problem using such an conversion

         (short?)(Convert.ToInt16(dr["watermark"])