Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

asp.net - checking for Null values in datatables

Posted on 2010-11-17
4
Medium Priority
?
370 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
[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
  • 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 200 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 100 total points
ID: 34161087
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1700 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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