?
Solved

Conversion of string to type Double is invalid

Posted on 2009-05-07
5
Medium Priority
?
518 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
[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
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 2000 total points
ID: 24339579
>>>EroleIDs = +"'" + dtEroles.Rows(0)(0).ToString() + "'"
It may be caused by the =+ operation in the above line.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

762 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