[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
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
Re: [2005] Select Sum(test) and DBnull
You could use String.Empty in place of "" if you want it to look better.
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
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)
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 :-)
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.