Solved

Error when trying to add a variable to a database item

Posted on 2006-07-13
5
198 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 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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