Solved

asp.net - checking for Null values in datatables

Posted on 2010-11-17
4
364 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Programmatically storing deadlock graphs with SQL Server 6 40
mail.To.Add 5 24
MediaHelp 4 21
jquery datatables, asp.net MVC 9 38
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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, fr…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

815 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

12 Experts available now in Live!

Get 1:1 Help Now