?
Solved

Error when trying to add a variable to a database item

Posted on 2006-07-13
5
Medium Priority
?
202 Views
Last Modified: 2010-04-23
Why do I get an error when I try to add the foll:

Dim iNIS as Decimal
iNIS = iNIS + dr.Item("NIS")

I get the foll error:

Error      1      Operator '+' is not defined for types '1-dimensional array of Decimal' and 'Object'.      

How can I solve this so that I can do what I intended to do?

Secondly, What is used instead of the += statement in Visual Basic .NET 2005?

Thank you in advance!
0
Comment
Question by:OsirisJa
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17105976
Dim iNIS as Decimal
iNIS = iNIS + dr.Item("NIS").Value
0
 

Author Comment

by:OsirisJa
ID: 17106001
That doesn't work
0
 
LVL 5

Expert Comment

by:nickhoggard
ID: 17106082
Hi,

What about casting the datarow item first:

        iNis = iNis + CDec(dr.Item("NIS"))

Cheers

Nick
0
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 2000 total points
ID: 17106188
What is DR ?
Is it a DataReader object and is the column "NIS" of Decimal type
If yes
then I am baffled by the error you are getting
the lines
   Dim iNIS as Decimal
   iNIS = iNIS + dr.Item("NIS")
are perfectly fine
The Error talks of 1-Dimensional Array, I can't see any Array in here
Are you missing anything ??
Is it the line which is throwing the Error ??
try to Debug and check

Also += is a short form for incrementing a variable
for eg if we have
   Dim i As Integer = 10
and we want to Add say 5 to it
instead of
   i = i = 5
we can have
   i += 5
In fact += is the recommendded way of incrementing a variable
so your code could as well be
   iNIS += dr.Item("NIS")

similarly you have -=, &= (for concatenation) etc.
0
 

Author Comment

by:OsirisJa
ID: 17106336
Thank you very much arif.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses
Course of the Month16 days, 9 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question