Solved

Error when trying to add a variable to a database item

Posted on 2006-07-13
5
193 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 142

Expert Comment

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

Author Comment

by:OsirisJa
Comment Utility
That doesn't work
0
 
LVL 5

Expert Comment

by:nickhoggard
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
Thank you very much arif.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now