473,503 Members | 2,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7018
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
3609
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
6394
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
2167
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
623
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
1599
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
2296
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
1708
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
12414
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
8733
by: vinrin | last post by:
Thank for your answer. :-) call CheckEmptyNode (treeview) public void CheckEmptyNode( Object N ) { Microsoft.Web.UI.WebControls.TreeNode menuNode = null; ...
0
7188
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7063
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
5558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.