Solved

VB.Net - Referencing Decimal Type in DataTable

Posted on 2013-01-29
8
351 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…

839 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