Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Casting Difficulties

Posted on 2009-07-05
3
Medium Priority
?
350 Views
Last Modified: 2013-11-11
Hi Experts,

I have a LINQ expression that produces a single decimal number - 4201.00D.

The problem is, I cannot get this to be accepted into the textbox I have.

While the LINQ statement looks a little complicated (see below) it works and it delivers the number above. I cannot get my textbox to accept this number.

The error  I get is:

Conversion from type 'DataQuery(Of Decimal)' to type 'String' is not valid.

I have tried Ctype and trycast (trycast just gave me nothing).

So, my question is, how to you cast succesfully to allow a textbox to accept your LINQ statement result.

Kind Regards

Simon
Dim clientBalance = (From ledger In db.ledgers _
                                    Where (ledger.acc_id = "2" And ledger.tran_type = "CI" And ledger.payment_complete = False And ledger.client_no = clientNo) Or _
                                   (ledger.acc_id = "2" And ledger.tran_type = "PMT" And ledger.payment_complete = False And ledger.client_no = clientNo) _
                                    Select _
                                    balance = -1 * (From ledg2 In db.ledgers Where (ledg2.tran_type = "CI" And ledg2.acc_id = "2" And ledg2.payment_complete = False And ledg2.client_no = ledger.client_no) Select ledg2.amount).Sum - _
                                                    If((From ledg3 In db.ledgers Join ledg4 In db.ledgers On ledg3.posting_id Equals ledg4.link_posting_id Where _
                                                    (ledg3.acc_id = "2" And ledg3.payment_complete = False And ledg3.client_no = ledger.client_no) Select ledg4.amount).Count > 0, _
                                                    (From ledg3 In db.ledgers Join ledg4 In db.ledgers On ledg3.posting_id Equals ledg4.link_posting_id Where _
                                                    (ledg3.acc_id = "2" And ledg3.payment_complete = False And ledg3.client_no = ledger.client_no) Select ledg4.amount).Sum, _
                                                    (From ledg3 In db.ledgers Join ledg4 In db.ledgers On ledg3.posting_id Equals ledg4.link_posting_id Where _
                                                    (ledg3.acc_id = "2" And ledg3.payment_complete = False And ledg3.client_no = ledger.client_no) Select ledg4.amount).Count)).Distinct

Open in new window

0
Comment
Question by:si2030
[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 Comments
 
LVL 9

Assisted Solution

by:Hawkvalley1
Hawkvalley1 earned 400 total points
ID: 24779321
Have you tried:

textbox1.Text = clientBalance.ToString
0
 
LVL 7

Assisted Solution

by:Mohed Sharfi
Mohed Sharfi earned 400 total points
ID: 24779349
Hi si2030,
please try this code to cast decimal to string
thanks
decimal Mydecimal = 4201.00D;
string Mystr;
Object MyObject;
MyObject = Mystr; // put  into object
Mydecimal = ()MyObject; // two-step cast works
Mystr = (string) Mydecimal;
Mystr = (string)MyObject; // throws exception

Open in new window

0
 

Accepted Solution

by:
si2030 earned 0 total points
ID: 24779527
I have worked this out. It was a LINQ issue in that while I did use distinct it still treated the result as an array.. as per (0)4201.00D. By adding ".single" to the end of ".distinct" the result was transformed into a single item.
0

Featured Post

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
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: …

730 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