从字符串“String”转换输入'Double'无效。 [英] Conversion from string "String" to type 'Double' is not valid.

查看:164
本文介绍了从字符串“String”转换输入'Double'无效。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai我在查询字符串中传递值,当我收到此错误时,这是​​我的代码:



hai i am passing the Value in query string ,at the time i am receiving this error this is my code:

Protected Sub Submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Submit.Click
        Try
            oDr = oMainForm.oConn.RunQuery("insert into BUSON_ASSIGN(Callid,ClientId,CallSubject,CallDescription,Priority,CallType,Status,FeedBack,RspDateTime,Assignto)values('" + txtCallId.Text + "','" + ClientId.SelectedValue + "','" + CallSubject.Text + "','" + CallDesc.Text + "','" + Priority.SelectedValue + "','" + CallType.SelectedValue + "','" + CallStatus.SelectedValue + "','" + Feedback.Text + "', getDate() ,' " + DropDownConsultant.SelectedItem.Text() + "')")
            Errlbl0.Text = ""

            Dim Body As String = Me.PopulateBody("Hello", _
                                                 "I am Assign one Call Log for You Please Click Hear to View the Call Log", _
                                                "http://localhost:3482/AssignReport.aspx?UserId=" + txtCallId.Text + "&AssName" = +DropDownConsultant.SelectedItem.Text & _
                                               "", _
            ("" & _
            " " & _
            ""))//hear only i amgeting error
            Me.SendHtmlFormattedEmail("recipient@gmail.com", "Reg Serives Call!", Body)
            MsgBox("Your assign the Call log Your assign the case successfully!!!")
            Response.Redirect("AllCallReport.aspx")
        Catch ex As Exception
            Errlbl0.Text = ex.Message.ToString()

        End Try
    End Sub

推荐答案

使用 cdbl 函数,其中require要将字符串转换为double:

如同在您的代码中假设,如果字段 CallID ClientId 在数据库中是双重类型然后



cdbl(txtCallId.Text)和

cdbl(ClientId.SelectedValue)
Use cdbl function where require to convert string into double:
Like suppose in your code, if field CallID and ClientId are of double type in database then

cdbl(txtCallId.Text) and
cdbl(ClientId.SelectedValue)


错误告诉您问题,您使用的某些值是字符串格式,但它们必须是double类型。



如果不知道你的桌子结构,我想以下应该是双打:



tx tCallId.Text,

ClientId.SelectedValue




我还建议你查看如何在sql查询中使用参数因为您基于此代码通过表单非常容易受到SQL注入攻击。

Google搜索结果 [ ^ ]



如果你想保持你的代码不变,我建议使用Double.Parse()方法将相关的字符串值转换为double值,看看你是如何继续的。
Well the error tells you the issue, some of your values that you are using are in the format of a string, but they need to be as a type double.

Without knowing your table structure, I would imagine the following are supposed to be doubles:

txtCallId.Text,
ClientId.SelectedValue


I would also suggest you look up how to user parameters in your sql queries as you are very susceptible to SQL Injection attacks through your form based on this code.
(Google search results[^]

If you want to keep your code as it is, I would suggest using the Double.Parse() method to convert the relevant string values to double values and see how you get on.


这篇关于从字符串“String”转换输入'Double'无效。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆