?
Solved

specified cast is not valid when i delete the decimal amount value from my cell i datagridview

Posted on 2009-02-12
5
Medium Priority
?
583 Views
Last Modified: 2012-08-14
I get error message saying that the specified cast is not valid when i delete the decimal amount value from my cell i datagridview and click in another cell the error message shows upp saying that the specified cast is not valid....

The grid cell contain a decimal value 0.00 , and it happens when i delete value and click in another cell....
if ( row.RowState != DataRowState.Detached)
                    if ((int)row.AccountRow.Type >= 128)
                    {
                        sumRegisteredRight += row.Amount;  //    ERROR ON THIS LINE
                    }
                    else
                    {
                        sumRegisteredLeft += row.Amount;
                    }

Open in new window

0
Comment
Question by:Adnan
  • 3
  • 2
5 Comments
 

Author Comment

by:Adnan
ID: 23621073
here is the full function...
 private decimal GetSumRegistered( ref decimal sumRegisteredLeft, ref decimal sumRegisteredRight)
        {
            sumRegisteredRight = 0;
            sumRegisteredLeft = 0;
 
            foreach (DsReconItems.MatchItemRow row in dsReconItems1.MatchItem)
            {
                if ( row.RowState != DataRowState.Detached)
                    if ((int)row.AccountRow.Type >= 128)
                    {
                        sumRegisteredRight += row.Amount;
                    }
                    else
                    {
                        sumRegisteredLeft += row.Amount;
                    }
            }
            return sumRegisteredLeft + sumRegisteredRight;
        }

Open in new window

0
 

Author Comment

by:Adnan
ID: 23621225
Specified cast is not valid, when column returns NULL or is empety.....??

HELP PLEEAASSEEE...
0
 
LVL 11

Expert Comment

by:Vivek Thangaswamy
ID: 23622147
Your facing this problem due to nullable and type casting. Please follow the following discussion and solve your problem
http://www.developmentnow.com/g/36_2008_2_0_0_1051275/Nullable-types-giving-error.htm
 
 
0
 

Author Comment

by:Adnan
ID: 23622305
here is the correct answer for my prob......thank anyway experts....HUHHHH

 if ( row.RowState != DataRowState.Detached && row["Amount"] != DBNull.Value)
0
 
LVL 11

Accepted Solution

by:
Vivek Thangaswamy earned 2000 total points
ID: 23622376
Yes. this is what explained in that discussion.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question