Solved

Conversion of string to type Double is invalid

Posted on 2009-05-07
5
514 Views
Last Modified: 2012-06-27
Hello Experts,

When I try to build a string based on the datatable and datarow

I am getting an error
"Conversion from string "'" to type 'Double' is not valid."

I am not converting anything to Double I am just building the string

Please help


Dim EroleIDs as string
EroleIDs="" 
For Each dr In dtEroles.Rows
                    If EroleIDs.Length > 0 Then EroleIDs += ","
                    EroleIDs = +"'" + dtEroles.Rows(0)(0).ToString() + "'"
                Next

Open in new window

0
Comment
Question by:rowmark
5 Comments
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 24332713
Hi rowmark,
Try use "&" sign instead of "+" for the string combinations.
eg:
For Each dr In dtEroles.Rows
                    If EroleIDs.Length > 0 Then EroleIDs &= ","
                    EroleIDs &= "'" & dtEroles.Rows(0)(0).ToString() & "'"
                Next
0
 
LVL 3

Expert Comment

by:DreamsTech
ID: 24333076
I wrote a sample code : which worked correctly ,so it will double gets converted into string. The only reason it fails when the vulue you are trying to convert is not a number Or a null value
Dim str As String = ""
 Dim dt As New DataTable
        dt.Columns.Add("test")
        Dim dr As DataRow
        dr = dt.NewRow()
        dr("test") = "DoubleString"
        dt.Rows.Add(dr)
 
For Each dr1 As DataRow In dt.Rows
            str += str + "'" + dr1(0).ToString() + "'"
        Next

Open in new window

0
 
LVL 3

Expert Comment

by:DreamsTech
ID: 24333085
Ingnore my decs ,the only i thing i wanted to convey is ,the above code works fine ,still i in your foreach loop u looping the same row again n again ,the correct syntax wud be

or Each dr In dtEroles.Rows
                    If EroleIDs.Length > 0 Then EroleIDs += ","
                    EroleIDs = +"'" +  dr(0).ToString() + "'"  
                Next

try correcting this and let me know if this helps
0
 
LVL 3

Expert Comment

by:channa_m
ID: 24338360

 Try

dr(0).ToString() instead of   dtEroles.Rows(0)(0).ToString()
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 24339579
>>>EroleIDs = +"'" + dtEroles.Rows(0)(0).ToString() + "'"
It may be caused by the =+ operation in the above line.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

815 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

8 Experts available now in Live!

Get 1:1 Help Now