Solved

Conversion of string to type Double is invalid

Posted on 2009-05-07
5
513 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

14 Experts available now in Live!

Get 1:1 Help Now