Solved

extremely easy

Posted on 2012-03-30
9
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
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
 

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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