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 38:             MySqlDataAdapter da = new MySqlDataAdapter("select * from album_category order by catid asc", con);
Line 39:             DataSet ds = new DataSet();
Line 40:             da.Fill(ds);
Line 41:             rep_gallery.DataSource = ds;
Line 42:             rep_gallery.DataBind();

Source File: C:\Inetpub\vhosts\virajsmartsolutions.com\httpdocs\Gallery_Album.aspx.cs    Line: 40

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) +474
   MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection) +370
   MySql.Data.MySqlClient.MySqlConnection.Open() +507
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +182
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +180
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +126
   Gallery.Bind_imagegallery() in C:\Inetpub\vhosts\virajsmartsolutions.com\httpdocs\Gallery_Album.aspx.cs:40
   Gallery.Page_Load(Object sender, EventArgs e) in C:\Inetpub\vhosts\virajsmartsolutions.com\httpdocs\Gallery_Album.aspx.cs:29
   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.4494.0