Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 529
  • Last Modified:

Conversion of string to type Double is invalid

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
rowmark
Asked:
rowmark
1 Solution
 
David H.H.LeeCommented:
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
 
DreamsTechCommented:
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
 
DreamsTechCommented:
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
 
channa_mCommented:

 Try

dr(0).ToString() instead of   dtEroles.Rows(0)(0).ToString()
0
 
prairiedogCommented:
>>>EroleIDs = +"'" + dtEroles.Rows(0)(0).ToString() + "'"
It may be caused by the =+ operation in the above line.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now