|
-
Jan 1st, 2008, 01:04 AM
#1
Thread Starter
Lively Member
[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
-
Jan 1st, 2008, 01:16 AM
#2
Thread Starter
Lively Member
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
-
Jan 1st, 2008, 01:26 AM
#3
Frenzied Member
Re: [2005] Select Sum(test) and DBnull
You could use String.Empty in place of "" if you want it to look better.
-
Jan 1st, 2008, 04:57 AM
#4
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:
If rsTrans.Fields("totalinc").Value IsNot DBNull.Value Then
-
Jan 1st, 2008, 05:40 AM
#5
Thread Starter
Lively Member
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)
-
Jan 1st, 2008, 05:50 AM
#6
Thread Starter
Lively Member
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 :-)
-
Jan 1st, 2008, 06:35 AM
#7
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|