Hi, I keep on receiving this error when I click on the edit email link from the datagrid:Specified cast is not valid.
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: Specified cast is not valid.
Source Error:
Line 44: while (myReader.Read())
Line 45: {
Line 46: myEmail.id = myReader.GetInt32(0);
Line 47: myEmail.Title = myReader.GetString(1);
Line 48: myEmail.emailType = myReader.GetInt32(2);
Source File: c:\inetpub\wwwroot\cibt\datalayer\clsemail.cs Line: 46
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
System.Data.SqlClient.SqlDataReader.GetSqlInt32(In t32 i)
System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i)
CIBT.dataLayer.clsEmail.getDetails() in c:\inetpub\wwwroot\cibt\datalayer\clsemail.cs:46
CIBT.Administration.EditEmail.populateEmail() in c:\inetpub\wwwroot\cibt\administration\editemail.a spx.cs:65
CIBT.Administration.EditEmail.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\cibt\administration\editemail.a spx.cs:54
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
Here is the code where the error occurs:public CIBT.businessLayer.clsEmail getDetails()
{
SqlConnection dbCon = new SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings["dbCon"]);
SqlCommand dbComm = new SqlCommand("sp_get_email_details",dbCon);
dbComm.CommandType = CommandType.StoredProcedure ;
dbComm.Parameters.Add("@id",SqlDbType.Int);
dbComm.Parameters[0].Value = myEmail.id;
//procedure sp_get_company_details
//@id int
dbCon.Open();
SqlDataReader myReader = dbComm.ExecuteReader(CommandBehavior.CloseConnecti on);
while (myReader.Read())
{
myEmail.id = myReader.GetInt32(0); myEmail.Title = myReader.GetString(1);
myEmail.emailType = myReader.GetInt32(2);
myEmail.Subject = myReader.GetString(3);
myEmail.Body = myReader.GetString(4);
myEmail.Notes = myReader.GetString(5);
}
return myEmail;
}