Solved

extremely easy

Posted on 2012-03-30
9
265 Views
Last Modified: 2012-03-30
if (int.Parse(ds.Tables[0].Rows[0]["stateID"].ToString()) != 0)

my stateID is int field on database table and if it is null that blow ups, how can I modify above?
0
Comment
Question by:1jaws
9 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 37788529
check it for being == DBNull.Value before using it.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 37788539
Try:

if (ds.Tables[0].Rows[0]["stateID"] != DBNull.Value && int.Parse(ds.Tables[0].Rows[0]["stateID"].ToString()) != 0)
{
...

Open in new window

0
 
LVL 22

Expert Comment

by:p_davis
ID: 37788540
if(ds.Tables[0].Rows.Count > 0 && ds.Tables[0]Rows[0]["stateID"] != DBNull.Value)
{
if (int.Parse(ds.Tables[0].Rows[0]["stateID"].ToString()) != 0)
{}
}
0
 
LVL 20

Expert Comment

by:n2fc
ID: 37788542
Use an if statement ahead of that one that tests for null first!
If null, take appropriate action and skip the conversions...
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Closing Comment

by:1jaws
ID: 37788555
thanks needed exactly this
0
 
LVL 22

Expert Comment

by:p_davis
ID: 37788578
some days -- i get headaches from trying to help around here. </whine>
0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 37788582
Why You No Use Int.TryParse? [Weekend fun;)]
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37788608
p_davis said this just before I did, so I think he should be in on the solution as well. I just posted the example before he did  = )
0
 
LVL 22

Expert Comment

by:p_davis
ID: 37788617
s'all good.... but thanks anyway kaufmed
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now