Server Error in '/' Application.

Object cannot be cast from DBNull to other types.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Object cannot be cast from DBNull to other types.

Source Error:


Line 859:
Line 860:            rptcustomname = rptcustomname.Replace("  ", " ");
Line 861:            int publishyear = Convert.ToInt32(dt.Rows[0]["PublishYear"]);
Line 862:            string reporttype = Convert.ToString(dt.Rows[0]["reporttype"]);
Line 863:            lblReportType.Text = reporttype;

Source File: d:\inetpub\vhosts\reportbanana.com\httpdocs\reports_details.aspx.cs    Line: 861

Stack Trace:


[InvalidCastException: Object cannot be cast from DBNull to other types.]
   System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider) +55
   System.Convert.ToInt32(Object value) +31
   reports_details.GetData() in d:\inetpub\vhosts\reportbanana.com\httpdocs\reports_details.aspx.cs:861
   reports_details.Page_Load(Object sender, EventArgs e) in d:\inetpub\vhosts\reportbanana.com\httpdocs\reports_details.aspx.cs:126
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +52
   System.Web.UI.Control.OnLoad(EventArgs e) +97
   System.Web.UI.Control.LoadRecursive() +61
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +693


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4700.0