Home > Archive > ASP > January 2007 > Adding Different Fields
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Adding Different Fields
|
|
| Mangler 2007-01-30, 6:56 pm |
| Say I have to different recordsets that have the fields:
rsA.Fields.Item("A").Value ,rsB.Fields.Item("B").Value
How would I add those to fields? It may be my inexperience but when I
tried something like
rsA.Fields.Item("A").Value + rsB.Fields.Item("B").Value
didnt work because one of the fields was a empty value. I have about
6 fields i need to add together if a value exists in any of them.
Suggestions?
Respectfully,
Danny
| |
| Jon Paal 2007-01-30, 6:56 pm |
| test them first :
If Not IsNull(fielda) and Not IsNull(fieldb) then ....
"Mangler" <dwaldman@aspdevil.com> wrote in message news:1170175166.140204.39960@p10g2000cwp.googlegroups.com...
> Say I have to different recordsets that have the fields:
> rsA.Fields.Item("A").Value ,rsB.Fields.Item("B").Value
>
> How would I add those to fields? It may be my inexperience but when I
> tried something like
>
> rsA.Fields.Item("A").Value + rsB.Fields.Item("B").Value
>
> didnt work because one of the fields was a empty value. I have about
> 6 fields i need to add together if a value exists in any of them.
>
> Suggestions?
>
> Respectfully,
>
> Danny
>
| |
| Mangler 2007-01-30, 6:56 pm |
|
On Jan 30, 11:49 am, "Jon Paal" <Jon nospam Paal @ everywhere dot com>
wrote:
> test them first :
>
> If Not IsNull(fielda) and Not IsNull(fieldb) then ....
>
Tried this, maybe i am wrong here:
<% If Not IsNull(rsR.Fields.Item("price").Value) and Not
IsNull(rsRef.Fields.Item("price").Value) Then Response.Write
rsR.Fields.Item("price").Value + rsRef.Fields.Item("price").Value End
If %>
Keep getting a mismatch error...
| |
| Bob Barrows [MVP] 2007-01-30, 6:56 pm |
| Mangler wrote:
> Say I have to different recordsets that have the fields:
> rsA.Fields.Item("A").Value ,rsB.Fields.Item("B").Value
>
> How would I add those to fields? It may be my inexperience but when I
> tried something like
>
> rsA.Fields.Item("A").Value + rsB.Fields.Item("B").Value
>
> didnt work because one of the fields was a empty value. I have about
> 6 fields i need to add together if a value exists in any of them.
>
1. Modify the sql statements that produce the recordset to ensure the
fields do not contain Nulls. The details depend on the database you are
using. For example, SQL Server has the COALESCE function that can be
used to return either the value, or 0 if the value is Null.
2. Assign the values to variables (GPB*), check to see if they have
values and, if not, set them to 0 (zero) before adding them
*Good Programming Practice
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
| |
| Jon Paal 2007-01-30, 6:56 pm |
| Type mismatch is a general error that happens when you try to stuff one type of value into a variable of another type.
Let's say you are working with numbers, adding and subtracting them. You're working with
LowVal
HighVal
NewVal
And then at some point you say something like
HighVal = "XYZZY"
your operations are soon going to fail with a type mismatch error.
The easiest way to figure out where you went wrong is to do a response.write of each value along the path. That way you can see
exactly what each value is set to, and figure out which one is getting in a "bad" value.
"Mangler" <dwaldman@aspdevil.com> wrote in message news:1170177372.462234.168910@q2g2000cwa.googlegroups.com...
>
>
> On Jan 30, 11:49 am, "Jon Paal" <Jon nospam Paal @ everywhere dot com>
> wrote:
> Tried this, maybe i am wrong here:
>
> <% If Not IsNull(rsR.Fields.Item("price").Value) and Not
> IsNull(rsRef.Fields.Item("price").Value) Then Response.Write
> rsR.Fields.Item("price").Value + rsRef.Fields.Item("price").Value End
> If %>
>
> Keep getting a mismatch error...
>
| |
| Dave Anderson 2007-01-30, 6:56 pm |
| Mangler wrote:
> Say I have to different recordsets that have the fields:
> rsA.Fields.Item("A").Value ,rsB.Fields.Item("B").Value
>
> How would I add those to fields? It may be my inexperience but when I
> tried something like
>
> rsA.Fields.Item("A").Value + rsB.Fields.Item("B").Value
>
> didnt work because one of the fields was a empty value. I have about
> 6 fields i need to add together if a value exists in any of them.
>
> Suggestions?
SQL ISNULL is a good choice to ensure you always have a value in your field:
http://msdn2.microsoft.com/en-us/library/aa933210(SQL.80).aspx
It is also worth pointing out that JScript conditional assignment makes this
quite trivial:
(rsA.Fields("A").Value || DEFAULT_VALUE) + ...
You have to set your default value according to type, of course. For
example:
rs.Fields("Quantity").Value || 0
rs.Fields("Address2").Value || ""
rs.Fields("Validated").Value || false
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
| |
| Mangler 2007-01-31, 6:56 pm |
| On Jan 30, 12:44 pm, "Dave Anderson" <NYRUMTPEL...@spammotel.com>
wrote:
> rs.Fields("Quantity").Value || 0
I tried assigning the defult value like the above example and kept
getting an error saying invalid character. I did however get what I
need done to work. Just put some hidden fields with the recordset as
the value and called a javascript function to add the fields.
|
|
|
|
|