?
Solved

VB.Net - Referencing Decimal Type in DataTable

Posted on 2013-01-29
8
Medium Priority
?
359 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 1000 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

830 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