[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
Solved

# Error when trying to add a variable to a database item

Posted on 2006-07-13
Medium Priority
201 Views
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?

0
Question by:OsirisJa
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 143

Expert Comment

ID: 17105976
Dim iNIS as Decimal
iNIS = iNIS + dr.Item("NIS").Value
0

Author Comment

ID: 17106001
That doesn't work
0

LVL 5

Expert Comment

ID: 17106082
Hi,

What about casting the datarow item first:

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

Cheers

Nick
0

LVL 19

Accepted Solution

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
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

ID: 17106336
Thank you very much arif.
0

## Featured Post

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
###### Suggested Courses
Course of the Month12 days, 21 hours left to enroll