Solved

Conversion of string to type Double is invalid

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

13 Experts available now in Live!

Get 1:1 Help Now