[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
5
Medium Priority
?
201 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
[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
  • Learn & ask questions
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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.
Video by: ITPro.TV
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

650 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