Solved

VB.Net - Referencing Decimal Type in DataTable

Posted on 2013-01-29
8
353 Views
Last Modified: 2013-01-30
Good Day Experts!

I am iterating through a DataTable referencing values in it for a select query.

Here is the portion of the select query where sqlRSGetLineItems is the DataRow in the below For Each loop:

[BATCH NUMBER]='" & sqlRSGetLineItems("BATCH NUMBER").Value & "''

For Each sqlRSGetLineItems In sqlRStbl.Rows

Next

Issue I have is that "BATCH NUMBER" is decimal.  So how do I reference it for use in the query? I am getting an error since I am using .Value.

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 250 total points
ID: 38833061
Try CDec(sqlRSGetLineItems("BATCH NUMBER").Value.Tostring("f2"))

The f2 is just for 2 decimal Places...
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 250 total points
ID: 38833166
I think the reason for error is that you are enclosing it in ' ' which is for varchar type

Change

[BATCH NUMBER]='" & sqlRSGetLineItems("BATCH NUMBER").Value & "''

to

[BATCH NUMBER]=" & sqlRSGetLineItems("BATCH NUMBER").Value
0
 

Author Comment

by:Jimbo99999
ID: 38835293
This may sound odd but...

I don't even have an understanding how/why I have to do the converting and .Value or .ToString.  

Are there rules anywhere that can guide me?

I spent hours and hours converting this code using .Value.  At the time I thought it was right since I didnt get any syntax errors.  But now everywhere I have it I get an error when I run it.

Thanks,
jimbo99999
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38835367
Did you see my comment?
0
 

Author Comment

by:Jimbo99999
ID: 38835554
After reviewing your response and jtoutou's, I had to use the following combination to get the code to work:

[BATCH NUMBER]='" & CDec(sqlRSGetLineItems("BATCH NUMBER").ToString) & "'
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 38835852
Are you satisfied with the code?
0
 

Author Comment

by:Jimbo99999
ID: 38836287
It works.  Why do you ask? Am I missing something other than not understanding like in my post ID: 38835293?
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 38836313
No you do not missing something . Your are Combining Solutions so you have to accept multiple solutions to close the question
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

687 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