Solved

asp.net - checking for Null values in datatables

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 discusses moving either the default database or any database to a new volume.

708 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