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 62:             MySqlDataAdapter da = new MySqlDataAdapter("select * from product_brand where cid='" + cid + "' ", con);
Line 63:             DataSet ds = new DataSet();
Line 64:             da.Fill(ds);
Line 65:             rep_brandname.DataSource = ds;
Line 66:             rep_brandname.DataBind();

Source File: C:\Inetpub\vhosts\virajsmartsolutions.com\httpdocs\Metering_accessories.aspx.cs    Line: 64

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
   Metering_accessories.bind_Brands() in C:\Inetpub\vhosts\virajsmartsolutions.com\httpdocs\Metering_accessories.aspx.cs:64
   Metering_accessories.Page_Load(Object sender, EventArgs e) in C:\Inetpub\vhosts\virajsmartsolutions.com\httpdocs\Metering_accessories.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