Results 1 to 7 of 7

Thread: [2005] Select Sum(test) and DBnull

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    101

    [2005] Select Sum(test) and DBnull

    Hello

    I do a query that selects and sums some data.

    Problem is if there is nothing to sum it will still return one row full of dbnulls.

    This makes my program error when I try to compare with another number (because the value returned from the database is a null not a number)

    How can I check? I treid.

    If Not rsTrans.Fields("totalinc").Value = System.DBNull Then

    But that did not work.

    Thanks

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    101

    Re: [2005] Select Sum(test) and DBnull

    I did this

    If Not rsTrans.Fields("totalinc").Value.ToString = "" Then

    It seems to work but seems messy also

  3. #3
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2005] Select Sum(test) and DBnull

    You could use String.Empty in place of "" if you want it to look better.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Select Sum(test) and DBnull

    First of all, you should be using ADO.NET DataTables, not ADO Recordsets, unless you have a good reason. Secondly, System.DBNull is a type, not a value. If you want to check whether a field is null you do this:
    vb.net Code:
    1. If rsTrans.Fields("totalinc").Value IsNot DBNull.Value Then
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    101

    Re: [2005] Select Sum(test) and DBnull

    Thank you :-)

    I am needing to learn ado.net but found it seemed to take more code to do simple things.

    Perhaps I was doing it wrong.

    Thanks again

    :-)

    Edit:
    would someone have a good tutorial on how to use ado.net unbound? (like what I do with the above)

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    101

    Re: [2005] Select Sum(test) and DBnull

    OK, found this

    http://samples.gotdotnet.com/quickst...soverview.aspx

    are they good samples?

    I dont want to learn the wrong way :-)

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Select Sum(test) and DBnull

    ADO.NET and data-binding have nothing specific to do with each other. They are often used together, because you usually want to display the data you retrieve and data-binding is a convenient way to do that. The data you bind to your controls can come from anywhere though, and the data you get from your database can go anywhere. Think of ADO.NET and data-binding as two black boxes with holes in them for input and output. You can connect those wholes together, or you can connect either box to some other box.

    If you want some quick code examples of the most common ADO.NET scenarios then follow the Data Access link in my signature. There's also an ADO.NET tutorial somewhere on this site.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width