Solved

asp.net - checking for Null values in datatables

Posted on 2010-11-17
4
361 Views
Last Modified: 2012-06-27
This line is giving me, "Conversion from type 'DBNull' to type 'String' is not valid."

      strString = dt.Compute("SUM(Column1)", String.Empty)

How do I check for DBNull in a dataset?


Thank you.

0
Comment
Question by:Rick
  • 2
4 Comments
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 34160383
use IsDbNull method, check:
http://stackoverflow.com/questions/222834/handling-dbnull-data-in-vb-net

Note: is dt a datatable? Please provide more code
0
 
LVL 16

Assisted Solution

by:MikeMCSD
MikeMCSD earned 50 total points
ID: 34160637

If Not Column1.GetType() Is GetType(DBNull) Then
    strString = dt.Compute("SUM(Column1)", String.Empty)
End If
0
 
LVL 35

Assisted Solution

by:Miguel Oz
Miguel Oz earned 25 total points
ID: 34161087
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 425 total points
ID: 34162579
Change this

  strString = dt.Compute("SUM(Column1)", String.Empty)

to

Dim strObj as Object =  dt.Compute("SUM(Column1)", String.Empty)
If IsDBNull(strObj) Then
   strString = 0
Else
   strString = strObj
End If
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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

896 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

14 Experts available now in Live!

Get 1:1 Help Now