Solved

extremely easy

Posted on 2012-03-30
9
264 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 74

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 19

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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 74

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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 discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

20 Experts available now in Live!

Get 1:1 Help Now