Solved

VB.Net - Referencing Decimal Type in DataTable

Posted on 2013-01-29
8
348 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
  • 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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38835367
Did you see my comment?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 …
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now