1 Replies - 1258 Views - Last Post: 01 November 2012 - 01:30 AM Rate Topic: -----

#1 hiran1800  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 06-November 10

Conversion from string "" to type 'Double' is not vali

Posted 01 November 2012 - 01:04 AM

Error " Conversion from string "" to type 'Double' is not valid."
I think everything correct , but still error , Please help.

this line show error :
Dim newItem As New ListViewItem(New String() {i, cn.dr.Item("BgNo").ToString(), cn.dr.Item("BgDes").ToString(), cn.dr.Item("InUnit").ToString(), Fdate.formatNo(CDbl(cn.dr.Item("InQty").ToString())), Fdate.formatNo(CDbl(cn.dr.Item("InPrice").ToString())), cn.dr.Item("InCur").ToString(), Fdate.formatNo(CDbl(cn.dr.Item("InAmtCur").ToString())), Fdate.formatNo(CDbl(cn.dr.Item("InExRate").ToString())), Fdate.formatNo(CDbl(cn.dr.Item("InTTBaht").ToString())), cn.dr.Item("InNote").ToString(), cn.dr.Item("CostID").ToString(), cn.dr.Item("TranType").ToString(), cn.dr.Item("InACID").ToString(), cn.dr.Item("InLife").ToString(), Fdate.formatNo(CDbl(cn.dr.Item("InBGLine").ToString())), Fdate.formatNo(CDbl(cn.dr.Item("InBGCum").ToString()))})


Sub HaveRows2()

        Dim cn As New ClsCommand
        Dim sql As String

        sql = "  SELECT Tb_MRSControl.MrsNo, Tb_MRSControl.MrsDate,Tb_MRSControl.MrsUser,Tb_MRSControl.MrsFY,Tb_MRSControl.MrsRqID, " _
            & " Tb_MRSControl.MrsDpID, Tb_MRSControl.MrsSupNM, Tb_MRSControl.MrsRqDT, Tb_MRSControl.MrsObj,Tb_MRSControl.MrsVTrate,Tb_MRSControl.MrsOrigin, " _
            & " Tb_MRSControl.MrsCountry, Tb_MRSControl.MrsTTBFvat, Tb_MRSControl.MrsTTvat, Tb_MRSControl.MrsTTAFvat,Tb_MRSControl.MrsValid, " _
            & " Tb_MrsDetail.JobitemNo,Tb_MrsDetail.BgNo,Tb_MrsDetail.BgDes,Tb_MrsDetail.CostID,Tb_MrsDetail.Trantype,Tb_MrsDetail.InUnit, " _
            & " Tb_MrsDetail.InQty,Tb_MrsDetail.InPrice,Tb_MrsDetail.InAmtCur,Tb_MrsDetail.InCur,Tb_MrsDetail.InExRate,Tb_MrsDetail.InTTBaht, " _
            & " Tb_MrsDetail.InNote,Tb_MrsDetail.InLife,Tb_MrsDetail.InACID,Tb_MrsDetail.InBGLine,Tb_MrsDetail.InBGCum "

        sql = sql & " FROM (Tb_MrsControl LEFT JOIN Tb_MrsDetail ON Tb_MrsControl.MrsNo = Tb_MrsDetail.InMrsNo) "

        sql = sql & "  where  Tb_MrsControl.MrsNo ='" & txtMRSNO.Text & "'"

        cn.ReadData(sql)

        Dim i As Integer = 0
        ListViewBG1.Items.Clear()
        If cn.dr.HasRows <> 0 Then
      
            HV = True
            btBGSave.Text = ""
           
            'Try

            Do While cn.dr.Read

                i = ListViewBG1.Items.Count + 1
                If i = 1 Then

                    txtMRSDate.Value = cn.dr.Item("MrsDate").ToString()
                    txtUser.Text = cn.dr.Item("MrsUser").ToString()
                    txtMrsFY.Text = cn.dr.Item("MrsFY").ToString()
                    txtReqID.Text = cn.dr.Item("MrsRqID").ToString()
                    txtRQdept.Text = cn.dr.Item("MrsDpID").ToString()

                    txtSupName.Text = cn.dr.Item("MrsSupNm").ToString()
                    txtRQdate.Value = cn.dr.Item("MrsRqDT").ToString()
                    txtObj.Text = cn.dr.Item("MrsObj").ToString()
                    txtVatRate.Text = cn.dr.Item("MrsVTrate").ToString()
                    cboOrigin.Text = cn.dr.Item("MrsOrigin").ToString()
                    txtVatRate.Text = cn.dr.Item("MrsVTrate").ToString()
                    cboCountry.Text = cn.dr.Item("MrsCountry").ToString()
                    txtBGSubTT.Text = cn.dr.Item("MrsTTBFvat").ToString()
                    txtBGSubVat.Text = cn.dr.Item("MrsTTvat").ToString()
                    txtBGGrandTT.Text = cn.dr.Item("MrsTTAFvat").ToString()
                    txtST.Text = cn.dr.Item("MrsValid").ToString()


                End If

                Dim newItem As New ListViewItem(New String() {i, cn.dr.Item("BgNo").ToString(), cn.dr.Item("BgDes").ToString(), cn.dr.Item("InUnit").ToString(), Fdate.formatNo(CDbl(cn.dr.Item("InQty").ToString())), Fdate.formatNo(CDbl(cn.dr.Item("InPrice").ToString())), cn.dr.Item("InCur").ToString(), Fdate.formatNo(CDbl(cn.dr.Item("InAmtCur").ToString())), Fdate.formatNo(CDbl(cn.dr.Item("InExRate").ToString())), Fdate.formatNo(CDbl(cn.dr.Item("InTTBaht").ToString())), cn.dr.Item("InNote").ToString(), cn.dr.Item("CostID").ToString(), cn.dr.Item("TranType").ToString(), cn.dr.Item("InACID").ToString(), cn.dr.Item("InLife").ToString(), Fdate.formatNo(CDbl(cn.dr.Item("InBGLine").ToString())), Fdate.formatNo(CDbl(cn.dr.Item("InBGCum").ToString()))})
                Me.ListViewBG1.Items.Add(newItem)



            Loop


            CalGrandPrice()

            'Catch ex As Exception
            '    MsgBox(ex.Message)
            'End Try


        Else
            HV = False
            btBGSave.Text = ""
            

        End If
        cn.closedb()

    End Sub




Is This A Good Question/Topic? 0
  • +

Replies To: Conversion from string "" to type 'Double' is not vali

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 767
  • Joined: 19-October 11

Re: Conversion from string "" to type 'Double' is not vali

Posted 01 November 2012 - 01:30 AM

You're having problems with all your Fdate values, because they should be of String type ultimately (because you're adding them to New String(), and from there to ListViewItem, which accepts only String type values.

What you are doing with each Fdate is:
        cn.dr.Item("InQty").ToString() 'you are changing some (probably numeric) quantity to string
        CDbl(cn.dr.Item("InQty").ToString()) 'then you're trying to change this string to double



Let me clarify with example:
        Dim firstString As String = "first"
        Dim secondString As String = "second"
        Dim thirdString As String = "third"
        'this would work:
        Dim workingListViewItem As New ListViewItem(New String() {firstString, secondString, thirdString})
        'this won't work (but will show no error, if you have Option Strict Off, with Strict On, you'll get error immediately)
        Dim falseListViewItem As New ListViewItem(New String() {CDbl(firstString), secondString, CDbl(thirdString.ToString())})


This post has been edited by lucky3: 01 November 2012 - 01:31 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1