从字符串“”到“字节”类型的转换无效

时间:2011-10-25 03:06:16

标签: asp.net vb.net variable-assignment

我一直在努力解决这个错误几天,我已经过了代码试图找到一个错误类型的实例,但没有运气。单击提交按钮时,我收到“从字符串转换”“键入'字节'无效”。所以我的想法是Data_Save函数有问题。但我无法看到我的错误。任何帮助将不胜感激。

Protected Function Data_Save() As Boolean
    Data_Save = False
    Try

        Dim newTable As New DemoOp_WebDataTable
        Dim newRow As DemoOp_WebRow = newTable.NewRow()

        newRow.DOW_FName = Me.txtFName.Text
        newRow.DOW_LName = Me.txtLName.Text
        newRow.DOW_Addr_1 = Me.txtAddr_1.Text
        newRow.DOW_Addr_2 = Me.txtAddr_2.Text
        newRow.DOW_City = Me.txtCity.Text
        newRow.DOW_State = Me.ddState.SelectedValue.ToString
        newRow.DOW_Zip = Me.txtZip.Text
        newRow.DOW_Home_Phone = Me.txtHome_Phone.Text
        newRow.DOW_Work_Phone = String.Empty
        newRow.DOW_Cell_Phone = Me.txtCell_Phone.Text
        newRow.DOW_Email = Me.txtEmail.Text
        newRow.DOW_Dem_Exp = String.Empty
        newRow.DOW_Wkd_Ret = String.Empty
        newRow.DOW_Bilingual = String.Empty
        newRow.DOW_Lang_Spk = String.Empty
        newRow.DOW_Hrd_Store = Me.ddlOptQst12.SelectedItem.Value
        newRow.DOW_StoreCode = Me.ddAd_Code.SelectedValue.ToString
        newRow.DOW_In_Date = Now
        newRow.DOW_18Plus = Me.rblnewqst1.SelectedValue
        newRow.DOW_Transportation = Me.rblnewqst2.SelectedValue
        newRow.DOW_AbleToStand = Me.rblnewqst3.SelectedValue
        newRow.DOW_Internet = Me.rblnewqst4.SelectedValue
        newRow.DOW_DirectDeposit = Me.rblnewqst5.SelectedValue
        newRow.DOW_Experience = Me.rblnewqst6.SelectedValue
        newRow.DOW_Outgoing = Me.rblnewqst7.SelectedValue
        newRow.DOW_CulinarySkills = Me.rblnewqst8.SelectedValue
        newRow.DOW_DemoWorkType = Me.ddlOptQst1.SelectedItem.Value
        newRow.DOW_ReceiveTextMsgs = Me.rblOptQst2.SelectedValue
        newRow.DOW_AgeCategory = Me.ddlOptQst3.SelectedItem.Value
        newRow.DOW_ComputerSkill = Me.ddlOptQst4.SelectedItem.Value
        newRow.DOW_CookingSkill = Me.ddlOptQst5.SelectedItem.Value
        newRow.DOW_PhysicallyFit = Me.ddlOptQst6.SelectedItem.Value
        newRow.DOW_AreasOfExp = GetCheckValues(chkOptQst7)
        newRow.DOW_SpecialExpertise = GetCheckValues(chkOptQst8)
        newRow.DOW_OtherLanguage = Me.ddlOptQst9.SelectedItem.Value
        newRow.DOW_Felony = Me.rblnewqst11.SelectedValue
        newRow.DOW_SOffender = Me.rblnewqst12.SelectedValue
        newRow.DOW_ShopLift = Me.rblnewqst13.SelectedValue
        newRow.DOW_FoodHandlers = Me.rblnewqst10.SelectedValue
        newRow.DOW_OtherAgencies = GetCheckValues(chkOptQst10)
        newRow.DOW_CookingAppliances = GetCheckValues(chkOptQst11)      
        newRow.DOW_Hrd_Store_Detail = Me.ddlOptQst13.SelectedItem.Value


        Dim ta As DemoOp_WebTableAdapter = New DemoOp_WebTableAdapter

        'ta.Insert(newRow.DOW_FName, newRow.DOW_LName, newRow.DOW_Addr_1, newRow.DOW_Addr_2, newRow.DOW_City, _
        '    newRow.DOW_State, newRow.DOW_Zip, newRow.DOW_Home_Phone, newRow.DOW_Work_Phone, newRow.DOW_Cell_Phone, _
        '    newRow.DOW_Email, newRow.DOW_Dem_Exp, newRow.DOW_Wkd_Ret, newRow.DOW_Bilingual, newRow.DOW_Lang_Spk, _
        '    newRow.DOW_Hrd_Store, newRow.DOW_Hrd_Store_Detail, newRow.DOW_StoreCode, newRow.DOW_18Plus, newRow.DOW_Transportation, _
        '    newRow.DOW_AbleToStand, newRow.DOW_Internet, newRow.DOW_DirectDeposit, newRow.DOW_Felony, newRow.DOW_SOffender, newRow.DOW_ShopLift, newRow.DOW_Experience, _
        '    newRow.DOW_Outgoing, newRow.DOW_CulinarySkills, newRow.DOW_FoodHandlers, newRow.DOW_DemoWorkType, newRow.DOW_ReceiveTextMsgs, _
        '    newRow.DOW_AgeCategory, newRow.DOW_ComputerSkill, newRow.DOW_CookingSkill, newRow.DOW_PhysicallyFit, _
        '    newRow.DOW_AreasOfExp, newRow.DOW_SpecialExpertise, newRow.DOW_OtherAgencies, newRow.DOW_CookingAppliances, newRow.DOW_OtherLanguage)

        ta.Insert(newRow.DOW_FName, newRow.DOW_LName, newRow.DOW_Addr_1, newRow.DOW_Addr_2, newRow.DOW_City, _
                      newRow.DOW_State, newRow.DOW_Zip, newRow.DOW_Home_Phone, newRow.DOW_Work_Phone, newRow.DOW_Cell_Phone, _
                      newRow.DOW_Email, newRow.DOW_Dem_Exp, newRow.DOW_Wkd_Ret, newRow.DOW_Bilingual, newRow.DOW_Lang_Spk, _
                      newRow.DOW_Hrd_Store, newRow.DOW_StoreCode, newRow.DOW_18Plus, newRow.DOW_Transportation, _
                      newRow.DOW_AbleToStand, newRow.DOW_Internet, newRow.DOW_DirectDeposit, newRow.DOW_Experience, _
                      newRow.DOW_Outgoing, newRow.DOW_CulinarySkills, newRow.DOW_DemoWorkType, newRow.DOW_ReceiveTextMsgs, _
                      newRow.DOW_AgeCategory, newRow.DOW_ComputerSkill, newRow.DOW_CookingSkill, newRow.DOW_PhysicallyFit, _
                      newRow.DOW_AreasOfExp, newRow.DOW_SpecialExpertise, newRow.DOW_OtherLanguage, newRow.DOW_Felony, newRow.DOW_SOffender, newRow.DOW_ShopLift, newRow.DOW_FoodHandlers, newRow.DOW_OtherAgencies, newRow.DOW_CookingAppliances, newRow.DOW_Hrd_Store_Detail)

        Data_Save = True

    Catch ex As ApplicationException
        Me.lblErrMessage.Text = ex.InnerException.ToString
    End Try

End Function

Protected Function GetCheckValues(ByVal chklst As CheckBoxList) As String
    GetCheckValues = String.Empty

    Dim i As Integer
    Dim sb As StringBuilder = New StringBuilder()
    For i = 0 To chklst.Items.Count - 1
        If chklst.Items(i).Selected Then
            sb.Append(chklst.Items(i).Value & ",")
        End If
    Next
    'remove the last comma in sb
    If sb.Length > 0 Then
        Dim InputValue As String
        InputValue = Left(sb.ToString(), Len(sb.ToString()) - 1)
        GetCheckValues = InputValue
    End If

End Function

Protected Sub Reset_Controls()
    btnSubmit.Visible = False
    btnCancel.Visible = False
    btnBack.Visible = True

    txtFName.Enabled = False
    txtLName.Enabled = False
    txtAddr_1.Enabled = False
    txtAddr_2.Enabled = False
    txtCity.Enabled = False
    ddState.Enabled = False
    txtZip.Enabled = False
    txtHome_Phone.Enabled = False
    txtCell_Phone.Enabled = False
    txtEmail.Enabled = False
    ddlOptQst12.Enabled = False
    ddlOptQst13.Enabled = False
    ddStoreCode.Enabled = False

    rblnewqst1.Enabled = False
    rblnewqst2.Enabled = False
    rblnewqst3.Enabled = False
    rblnewqst4.Enabled = False
    rblnewqst5.Enabled = False
    rblnewqst6.Enabled = False
    rblnewqst7.Enabled = False
    rblnewqst8.Enabled = False
    rblnewqst10.Enabled = False
    rblnewqst11.Enabled = False
    rblnewqst12.Enabled = False
    rblnewqst13.Enabled = False
    ddlOptQst1.Enabled = False
    rblOptQst2.Enabled = False
    ddlOptQst3.Enabled = False
    ddlOptQst4.Enabled = False
    ddlOptQst5.Enabled = False
    ddlOptQst6.Enabled = False
    chkOptQst7.Enabled = False
    chkOptQst8.Enabled = False
    ddlOptQst9.Enabled = False
    chkOptQst10.Enabled = False
    chkOptQst11.Enabled = False

End Sub

Protected Sub btnOKMsg_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    If Data_Save() Then
        lblErrMessage.Text = "Your information has been submitted!"
    Else
        lblErrMessage.Text = "Error occurred while saving your entry. Click on 'Back' to return to main page."
    End If
    'Reset_Controls()
    ModalPopupExtender1.Hide()
End Sub

Protected Sub btnCancelMsg_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    lblErrMessage.Text = "Your information was previously submitted."
    ModalPopupExtender1.Hide()
End Sub

结束班

1 个答案:

答案 0 :(得分:2)

以下是一些可以帮助您入门的建议:

  • 在项目选项中启用“Option strict”并修复您可能遇到的任何错误。这将帮助您确定尝试使用空字符串设置字节值的位置。
  • 删除所有带有空catch部分的try-catch-statement。
  • 清理代码,并删除与您的问题无关的部分。
  • 告诉我们异常发生的位置和异常详情......