Solved

asp.net - checking for Null values in datatables

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

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 36

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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