By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,144 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,144 IT Pros & Developers. It's quick & easy.

System.InvalidCastException: Specified cast is not valid

P: 3
Server Error in '/Assignment' Application.
--------------------------------------------------------------------------------

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 94: sqlcom.Parameters["@Image"].Value=((TextBox)e.Item.Cells[2].Controls[0]).Text;
Line 95: sqlcom.Parameters["@Name"].Value=((TextBox)e.Item.Cells[3].Controls[0]).Text;
Line 96: sqlcom.Parameters["@Describes"].Value=((TextBox)e.Item.Cells[4].Controls[0]).Text;
Line 97: sqlcom.Parameters["@Money"].Value=((TextBox)e.Item.Cells[5].Controls[0]).Text;
Line 98: sqlcon.Open();


Source File: c:\inetpub\wwwroot\assignment1\rose.ascx.cs Line: 96

Stack Trace:


[InvalidCastException: Specified cast is not valid.]
Assignment.rose.dtgFlower_UpdateCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\assignment1\rose.ascx.cs:96
System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs e) +109
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs e) +507
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source, EventArgs e) +106
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +121
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1277




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
Dec 10 '07 #1
Share this Question
Share on Google+
2 Replies


codegecko
Expert 100+
P: 533
Hi thithi,

Firstly, welcome to TSDN. Please read our FAQ, especially our Posting Guidelines.

Secondly, please do not double-post your question as this clutters up our forum. I have deleted your other post for this purpose.

Thirdly, your question is ASP.NET-specific and has been moved to the .NET Forum (as the ASP forum is for classic ASP with VBScript as per this note which is displayed at the top of the forum).

Hopefully our .NET Experts can help you out on this issue.

Best regards,

medicineworker
Dec 10 '07 #2

Plater
Expert 5K+
P: 7,872
I would say that one of those cells is not actually a TextBox.
Why are you casting down to the control level anyway?
Does
Expand|Select|Wrap|Line Numbers
  1. e.Item.Cells[2].Value.ToString()
  2.  
not work?
Dec 10 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.