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 20:         MySqlConnection con = new MySqlConnection();
Line 21:         con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
Line 22:         con.Open();
Line 23:         MySqlCommand cmd = new MySqlCommand();
Line 24:         cmd.Connection = con;

Source File: c:\inetpub\vhosts\bookraja.com\missioncat.in\punjab100.aspx.cs    Line: 22

Stack Trace:


[InvalidCastException: Object cannot be cast from DBNull to other types.]
   System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider) +60
   MySql.Data.MySqlClient.Driver.LoadCharacterSets(MySqlConnection connection) +484
   MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection) +170
   MySql.Data.MySqlClient.MySqlConnection.Open() +523
   Default2.Page_Load(Object sender, EventArgs e) in c:\inetpub\vhosts\bookraja.com\missioncat.in\punjab100.aspx.cs:22
   System.Web.UI.Control.OnLoad(EventArgs e) +108
   System.Web.UI.Control.LoadRecursive() +90
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1533


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