Solved

Error when trying to add a variable to a database item

Posted on 2006-07-13
5
196 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 500 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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 …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

790 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