473,289 Members | 2,040 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,289 software developers and data experts.

Specified cast is not valid - please help

Can someone shed some light on my error here? Thanks!

Specified cast is not valid.

Exception Details: System.InvalidCastException: Specified cast is not
valid.

Source Error:

Stack Trace:

[InvalidCastException: Specified cast is not valid.]
milo.data.Storer.GetString(SqlDataReader reader, Type dataType,
String attributeName) in c:\inetpub\wwwroot\milo.data\storer.cs:572
milo.web.TextBox.SetValue(SqlDataReader reader) in
C:\Inetpub\wwwroot\milo.web\TextBox.cs:33
milo.data.Storer.LoadData(String filter) in
c:\inetpub\wwwroot\milo.data\storer.cs:393
milo.web.Storer.LoadData(String filter) in
c:\inetpub\wwwroot\milo.web\storer.cs:63
cms.user.information.Page_Load(Object sender, EventArgs e) in
C:\cms\user\information.aspx.cs:96
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
Nov 17 '05 #1
4 7000
AW
Your application is making an invalid cast, for instance:
int a =3;
string s;
s=(string)a;

If you want more info, post the code of your milo.data.Storer.GetString()
method in storer.cs.
--
To reply, remove a "l" before the @ sign.

AW - MCT, MCSD.Net, MCAD.Net
Nov 17 '05 #2
"Tyro" <lo******@yahoo.com> wrote in message
news:24*************************@posting.google.co m...
Can someone shed some light on my error here? Thanks!

Specified cast is not valid.

Exception Details: System.InvalidCastException: Specified cast is not
valid.

Source Error:

Stack Trace:

[InvalidCastException: Specified cast is not valid.]
milo.data.Storer.GetString(SqlDataReader reader, Type dataType,
String attributeName) in c:\inetpub\wwwroot\milo.data\storer.cs:572


Is it possible that the field you're retrieving is NULL?
--
John
Nov 17 '05 #3
>
If you want more info, post the code of your milo.data.Storer.GetString()
method in storer.cs.


public static string GetString(SqlDataReader reader, milo.data.Type
dataType, string attributeName)
{
int index = reader.GetOrdinal(attributeName);

if (reader.IsDBNull(index)==false)
{
try
{
if (dataType == milo.data.Type.STRING)
{
return (string)reader[attributeName];
}
else
{
switch((int)dataType)
{
case (int)milo.data.Type.INT_16:
return reader.GetInt16(index).ToString();
case (int)milo.data.Type.INT_32:
return reader.GetInt32(index).ToString();
case (int)milo.data.Type.INT_64:
return reader.GetInt64(index).ToString();
case (int)milo.data.Type.DECIMAL:
return reader.GetDecimal(index).ToString();
case (int)milo.data.Type.DOUBLE:
return reader.GetDouble(index).ToString();
case (int)milo.data.Type.FLOAT:
return reader.GetFloat(index).ToString();
case (int)milo.data.Type.BOOLEAN:
return reader.GetBoolean(index).ToString();
/* case (int)milo.data.Type.CHARS:
return reader.GetChars(index).ToString();*/
case (int)milo.data.Type.BYTE:
return reader.GetByte(index).ToString();
/* case (int)milo.data.Type.BYTES:
return reader.GetBytes(index).ToString();*/
}
}
}
catch(System.Data.SqlTypes.SqlNullValueException)
{
return null;
}
}
else
{
return "";
}

return null;
}
Nov 17 '05 #4
AW
Hi Tyro,

There are potentially several lines for your error in your code. To begin
with, if your milo.data.Type is an enum like I suspect, don't cast it to an
int in your switch. Write something like:
switch(dataType)
{
case milo.data.Type.INT_16:
return reader.GetInt16(index).ToString();
case milo.data.Type.INT_32:

The error may come from another line. I suggest that you switch to debug
mode and reach the line where the exception is raised.
--
To reply, remove a "l" before the @ sign.

Arnaud Weil - MCT, MCSD.Net, MCAD.Net
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tao | last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and tried to test it out. I created an ASP.NET project using the wizard and tried to run it by hitting "F5". I got an exception:...
6
by: Biva | last post by:
Hello All, Please help. I get the following error from my webpage: System.InvalidCastException: Specified cast is not valid. at Time.MaintAtRiskProjects.UpdateProject(String Project, String...
3
by: VB Programmer | last post by:
I am setting up forms authentication. In my code I keep getting this error. Any ideas? Error.... Server Error in '/LandOLots' Application....
0
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
0
by: Alan Z. Scharf | last post by:
this question in datagrid group for several days with no repsonse. I'm hoping for an answer her because of greater activity in this group. No cross-posting intended. Thanks....
6
by: John-Arne Lillebø | last post by:
Hi. I run into this problem and i could need some help to solve it. The project is an ASP.NET Web project. Including code sample of the problem. Any idea what is causing the error message ?...
1
by: planet | last post by:
Hi, I wish I can solve this problem not having recode the sub. Here is goes: I got this error' specified cast is not valid' at the second line. from the code Sub...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
2
by: vinrin | last post by:
Thank for your answer. :-) call CheckEmptyNode (treeview) public void CheckEmptyNode( Object N ) { Microsoft.Web.UI.WebControls.TreeNode menuNode = null; ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
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...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...

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.