473,326 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Problems with stupid cast error ASP.NET

i am throwing a exception error:
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.

this is my code..

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">



<form id="Form1" runat="server">
<div style="text-align: center">
<div class="eventmonth">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Homework1ConnectionString2 %>"
SelectCommand="SELECT [ID], [starttime], [title], [description] FROM [Events]" ProviderName="<%$ ConnectionStrings:Homework1ConnectionString2.Provi derName %>"></asp:SqlDataSource>
<ec:EventCalendar runat="server" ID="eventscalendar" DataSourceID="SqlDataSource1"
BorderWidth="2px" DayField="starttime" CssClass="eventmonthtable" DayNameFormat="Full" BackColor="#C0C0FF" BorderColor="#8080FF" BorderStyle="Groove" Font-Size="1em">
<DayStyle CssClass="calcurrentmonth" BackColor="White" BorderColor="#8080FF" BorderStyle="Ridge" BorderWidth="1px" ForeColor="Navy" />
<DayHeaderStyle CssClass="caldays" BackColor="#8080FF" BorderColor="#E0E0E0" BorderStyle="Groove" />
<WeekendDayStyle CssClass="calweekend" />
<OtherMonthDayStyle CssClass="calothermonth" />
<DayEventTemplate>
<div style="padding: 3px;">
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%#Eval("title") %>' NavigateUrl='<%# "events.aspx?Eventid=" &Cstr( Eval("ID"))%>'
ToolTip='<%#CStr(Eval("description")) %>' /></div>
</DayEventTemplate>
<HeaderTemplate>
<table width="100%">
<tr align="center">
<td>
<asp:LinkButton ID="PrevMonth" runat="server" Text='<%# "&laquo; " & Container.PrevMonth.ToString("MMMM yyyy") %>'
CommandName="PrevMonth" />
</td>
<td>
<h3>
<asp:Label ID="label2" runat="server" Text='<%# Container.CurrentMonth.ToString("MMMM yyyy") %>' /></h3>
</td>
<td>
<asp:LinkButton ID="NextMonth" runat="server" Text='<%# Container.NextMonth.ToString("MMMM yyyy") & " &raquo;" %>'
CommandName="NextMonth" />
</td>
</tr>
</table>
</HeaderTemplate>
<TodayDayStyle CssClass="calcurrentday" />
<DayNumberStyle CssClass="dayNumber" />
</ec:EventCalendar>
</div>

</div>
</form>


&nbsp;</asp:Content>
Mar 31 '08 #1
3 1555
DrBunchman
979 Expert 512MB
Hi Zubulake,

This is a Classic ASP forum - as you're question relates to ASP.NET you'll receive better help if you post any future questions in the .NET forum.

Another couple of things: you've post isn't very easy to read. If you put code tags (using the little # button above the input box) it will list the code neatly with line numbers. Makes life easier for everyone!

Also would it be possible for you to give the particular line of code where the exception was thrown. As it's a cast error and I can see a couple of CStr's in your code it may be these that have caused the problem. Have you tried using the .ToString method here instead?

If you can let us know the affected line of code we may be able to help you.

Thanks,

Dr B
Mar 31 '08 #2
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="~/master.master" Title="Caledar" %><%@ Page Language="VB" MasterPageFile="~/master.master" Title="Caledar" %>
  2. <%@ Page Language="VB" MasterPageFile="~/master.master" Title="Caledar" %>
  3.  
  4. <%@ Register TagPrefix="ec" Namespace="ControlSample" Assembly="EventCalendar" %>
  5.  
  6. <asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
  7. <div>
  8.             <div class="eventmonth">
  9.                 &nbsp;<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Homework1.mdb" SelectCommand="SELECT [ID], [starttime], [title], [description] FROM [Events]"></asp:AccessDataSource>
  10.             <ec:EventCalendar runat="server" ID="EventCalendar1" DataSourceID="AccessDataSource1" 
  11.                  BorderWidth="2px" DayField="starttime" CssClass="eventmonthtable" DayNameFormat="Full" BackColor="#C0C0FF" BorderColor="#8080FF" BorderStyle="Groove" Font-Size="1em" FirstDayOfWeek="Default" VisibleDate="2008-03-31">
  12.                 <DayStyle CssClass="calcurrentmonth" BackColor="White" BorderColor="#8080FF" BorderStyle="Ridge" BorderWidth="1px" ForeColor="Navy" />
  13.                 <DayHeaderStyle CssClass="caldays" BackColor="#8080FF" BorderColor="#E0E0E0" BorderStyle="Groove" />
  14.                 <WeekendDayStyle CssClass="calweekend" />
  15.                 <OtherMonthDayStyle CssClass="calothermonth" />
  16.                 <DayEventTemplate>
  17.                     <div style="padding: 3px;">
  18.                         <asp:HyperLink ID="HyperLink1" runat="server" Text='<%#Eval("title") %>' NavigateUrl='<%# "events.aspx?Eventid=" &Cstr( Eval("ID"))%>'
  19.                             ToolTip='<%#CStr(Eval("description")) %>' /></div>
  20.                 </DayEventTemplate>
  21.                 <HeaderTemplate>
  22.                     <table width="100%">
  23.                         <tr align="center">
  24.                             <td>
  25.                                 <asp:LinkButton ID="PrevMonth" runat="server" Text='<%# "&laquo; " & Container.PrevMonth.ToString("MMMM yyyy") %>'
  26.                                     CommandName="PrevMonth" />
  27.                             </td>
  28.                             <td>
  29.                                 <h3>
  30.                                     <asp:Label ID="label2" runat="server" Text='<%# Container.CurrentMonth.ToString("MMMM yyyy") %>' /></h3>
  31.                             </td>
  32.                             <td>
  33.                                 <asp:LinkButton ID="NextMonth" runat="server" Text='<%# Container.NextMonth.ToString("MMMM yyyy") & " &raquo;" %>'
  34.                                     CommandName="NextMonth" />
  35.                             </td>
  36.                         </tr>
  37.                     </table>
  38.                 </HeaderTemplate>
  39.                 <TodayDayStyle CssClass="calcurrentday" />
  40.                 <DayNumberStyle CssClass="dayNumber" />
  41.             </ec:EventCalendar>
  42.         </div>
  43.  
  44.     </div>
  45. </asp:Content>
  46.  
  47.  
my error is:

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.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[InvalidCastException: Specified cast is not valid.]
ControlSample.EventCalendar.cacheDataInViewstate(D ataView dv) +259
ControlSample.EventCalendar.SetupRealData(IEnumera ble data) +331
ControlSample.EventCalendar.CreateChildControls(IE numerable dataSource, Boolean dataBinding) +176
System.Web.UI.WebControls.CompositeDataBoundContro l.PerformDataBinding(IEnumerable data) +59
System.Web.UI.WebControls.DataBoundControl.OnDataS ourceViewSelectCallback(IEnumerable data) +111
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +29
System.Web.UI.WebControls.DataBoundControl.Perform Select() +149
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +70
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +82
System.Web.UI.WebControls.CompositeDataBoundContro l.CreateChildControls() +69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +50
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041

Ok this is the error code. it doesnt say anything about a where it is at.. this is really frustrating..
Apr 1 '08 #3
DrBunchman
979 Expert 512MB
Hmmm.....I'd have thought it would be one of your CStr functions as that's the only explicit casting I can see you doing. If you comment out all instances of it like this one:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <asp:HyperLink ID="HyperLink1" runat="server" Text='<%#Eval("title") %>' NavigateUrl='<%# "events.aspx?Eventid=" &Cstr( Eval("ID"))%>'
  3. ToolTip='<%#CStr(Eval("description")) %>' />
Do you still get the error?

Dr B
Apr 7 '08 #4

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

Similar topics

2
by: fremenusul | last post by:
I orginally asked this question on friday, and made some progress, but now I am getting an error. What is the type of xmlProductName (check the runtime type in the debugger)? The debug output...
2
by: Lampa Dario | last post by:
Hi, where is this stupid error in this program? When I execute it, i receive a segmentation fault error. #include <stdio.h> int main(int argc, char *argv, char *env) { int i=0; int l=0; int...
8
by: NilsNilsson | last post by:
I wrote this: short s1 = 0; short s2 = 1; short s3 = s1 + s2; And gor this compile error message: Cannot implicitly convert type 'int' to 'short' What is wrong here?
3
by: Bill | last post by:
I am confused why I must cast an enum to a type int if I defined the enum as follows: enum COLUMNS :int { IP=0, MSG =1 } IMHO the compiler should be able to make the conversion without...
8
by: Daniel Groh | last post by:
I'm facing this error: Error Message:Specified cast is not valid. this line: char chrTipoPessoa = (char)sqlCmd.ExecuteScalar(); It should returns the letter "F" or "J"! but with (string) it...
5
by: Mac via DotNetMonster.com | last post by:
Hi all, I have a creating a my own tabpage class (MyTabPage) which inherits the .Net TabPage class. In the relevant event I want to loop through the collection of TabPages and then when I...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
7
by: JV | last post by:
I am running a large Access 2000 application (installed using Access Runtime) that uses many VB SendKeys, primarily to expand combo boxes On Enter. When trying to run it on Vista I get a...
10
by: Chris Becke | last post by:
In C and in older C++ compilers, you could write code like this void a(void** pp); // declare a function that takes a pointer to a pointer-to-void. struct I {}; // some struct. I *i1,**i2; //...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.