Adding Different Fields
am 30.01.2007 17:39:26 von Mangler
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
Re: Adding Different Fields
am 30.01.2007 17:49:13 von Jon Paal
test them first :
If Not IsNull(fielda) and Not IsNull(fieldb) then ....
"Mangler" 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
>
Re: Adding Different Fields
am 30.01.2007 18:16:14 von Mangler
On Jan 30, 11:49 am, "Jon Paal"
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...
Re: Adding Different Fields
am 30.01.2007 18:25:12 von reb01501
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.
Re: Adding Different Fields
am 30.01.2007 18:27:34 von Jon Paal
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" wrote in message news:1170177372.462234.168910@q2g2000cwa.googlegroups.com...
>
>
> On Jan 30, 11:49 am, "Jon Paal"
> 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...
>
Re: Adding Different Fields
am 30.01.2007 18:44:10 von Dave Anderson
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).as px
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.
Re: Adding Different Fields
am 31.01.2007 15:46:09 von Mangler
On Jan 30, 12:44 pm, "Dave Anderson"
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.