473,471 Members | 1,684 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

urgent asp.net invalid cast error

System.InvalidCastException: Specified cast is not valid.
hi i am received that error below is my code

result = new CustID(Convert.ToString(reader["CustID"]),
Line 57:
(DateTime)reader["BirthDate"],Convert.ToString(reader["Name"]),
Convert.ToString(reader["Sex"]), (Byte)reader["NameFormatCodeOri"],
Convert.ToString(reader["Address"]),
Convert.ToString(reader["PostCode"]));
First error was can not convert dbnull to string then i used
Convert.tostring and now i am getting that error not with all record but with
some records i assume dbnull value created some problem
thanks
Jun 7 '06 #1
1 1196
If some of your fields can have null values then you need to check for
DbNull values before accessing those values. You can convert a null value.

If (!Convert.IsDBNull(dr[......])
{
... do your stuff ...
}

"amjad" <am***@discussions.microsoft.com> wrote in message
news:DA**********************************@microsof t.com...
System.InvalidCastException: Specified cast is not valid.
hi i am received that error below is my code

result = new CustID(Convert.ToString(reader["CustID"]),
Line 57:
(DateTime)reader["BirthDate"],Convert.ToString(reader["Name"]),
Convert.ToString(reader["Sex"]), (Byte)reader["NameFormatCodeOri"],
Convert.ToString(reader["Address"]),
Convert.ToString(reader["PostCode"]));
First error was can not convert dbnull to string then i used
Convert.tostring and now i am getting that error not with all record but
with
some records i assume dbnull value created some problem
thanks

Jun 7 '06 #2

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

Similar topics

5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
1
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm...
0
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
3
by: scorpion53061 | last post by:
I have little hope of resolving this as I have had to contact outside help. But I thought I would post it here to see if anyone could add an idea or solution. 1. I have a form in a Class...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.