extremely easy

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?
1jawsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

p_davisCommented:
check it for being == DBNull.Value before using it.
0
käµfm³d 👽Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
p_davisCommented:
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
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

n2fcCommented:
Use an if statement ahead of that one that tests for null first!
If null, take appropriate action and skip the conversions...
0
1jawsAuthor Commented:
thanks needed exactly this
0
p_davisCommented:
some days -- i get headaches from trying to help around here. </whine>
0
Chinmay PatelChief Technical NinjaCommented:
Why You No Use Int.TryParse? [Weekend fun;)]
0
käµfm³d 👽Commented:
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
p_davisCommented:
s'all good.... but thanks anyway kaufmed
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.