类型1维数组的值不能转换为字符串视觉

时间:2017-11-10 19:05:45

标签: asp.net vb.net

在此威胁中帮助我完成每一行(Make a for each using SqlDataReader vb.net

但是当我想保存数据时(GM.AsigDupla(Txtfecha.Text, cboPlanta0.SelectedValue, cboPlanta0.SelectedItem.Text, cboAlmacen.SelectedValue, cboAlmacen.SelectedItem.Text, mater, lot

arrarys mater和lot显示错误的变量:类型1维数组的值不能转换为字符串

            Dim mater() As String
            Dim planta() As String
            Dim almacen() As String
            Dim lot() As String
            Dim cantidad() As String
            Dim cantadiat() As String
            Dim undad() As String
            Dim Cantidadc() As String
            Dim CantidadB() As String
            Dim Session1() As String
            Dim fecha() As String
            Dim RowCounter As Integer = 0
            RowCounter.ToString()




            Dim Con34 As New Data.SqlClient.SqlConnection
            Con34.ConnectionString = C.GetAppConfiguracion("Inventario", "ConnInventario")
            'Dim editCustQuery As String = "select Idmaterial , IdLote from s_RptInventarioSAP where idPlanta = '" & cboPlanta0.SelectedValue & "' and IdAlmacen = '" & cboAlmacen.SelectedValue & "'"
            Dim editCustQuery As String = "select * from dbo.s_RptInventarioSAP"
            Con34.Open()
            Dim CustCommand As New SqlCommand(editCustQuery, Con34)
            Dim sqladapter As SqlDataAdapter = New SqlDataAdapter(CustCommand)
            Dim tableresult As New DataTable(editCustQuery)

            sqladapter.Fill(tableresult)
            Con34.Close()
            For Each TableRow As DataRow In tableresult.Rows
                mater = tableresult.Rows.Item(RowCounter).Item(0)
                planta = tableresult.Rows.Item(RowCounter).Item(1)
                almacen = tableresult.Rows.Item(RowCounter).Item(2)
                lot = tableresult.Rows.Item(RowCounter).Item(3)
                cantidad = tableresult.Rows.Item(RowCounter).Item(4)
                cantadiat = tableresult.Rows.Item(RowCounter).Item(5)
                undad = tableresult.Rows.Item(RowCounter).Item(6)
                Cantidadc = tableresult.Rows.Item(RowCounter).Item(7)
                CantidadB = tableresult.Rows.Item(RowCounter).Item(8)
                Session1 = tableresult.Rows.Item(RowCounter).Item(9)
                fecha = tableresult.Rows.Item(RowCounter).Item(10)



                RowCounter = RowCounter + 1
            Next

            Dim resultado As String
            resultado = GM.AsigDupla(Txtfecha.Text, cboPlanta0.SelectedValue, cboPlanta0.SelectedItem.Text, cboAlmacen.SelectedValue, cboAlmacen.SelectedItem.Text, mater, lot)
            'i = i + 1
            With lbError0
                .Visible = True
                .Text = resultado
            End With


        Catch ex As Exception
            lbError0.Text = ex.Message

        End Try

    End If
End Sub

2 个答案:

答案 0 :(得分:0)

好的,我看到了一些错误。

        Dim mater() As String
        Dim planta() As String
        Dim almacen() As String
        Dim lot() As String
        Dim cantidad() As String
        Dim cantadiat() As String
        Dim undad() As String
        Dim Cantidadc() As String
        Dim CantidadB() As String
        Dim Session1() As String
        Dim fecha() As String
        Dim resultado() As String
        Dim RowCounter As Integer = 0




        Dim Con34 As New Data.SqlClient.SqlConnection
        Con34.ConnectionString = C.GetAppConfiguracion("Inventario", "ConnInventario")
        'Dim editCustQuery As String = "select Idmaterial , IdLote from s_RptInventarioSAP where idPlanta = '" & cboPlanta0.SelectedValue & "' and IdAlmacen = '" & cboAlmacen.SelectedValue & "'"
        Dim editCustQuery As String = "select * from dbo.s_RptInventarioSAP"
        Con34.Open()
        Dim CustCommand As New SqlCommand(editCustQuery, Con34)
        Dim sqladapter As SqlDataAdapter = New SqlDataAdapter(CustCommand)
        Dim tableresult As New DataTable(editCustQuery)

        sqladapter.Fill(tableresult)
        Con34.Close()
        For Each TableRow As DataRow In tableresult.Rows
            mater(RowCounter) = tableresult.Rows.Item(RowCounter).Item(0).toString
            planta(RowCounter) = tableresult.Rows.Item(RowCounter).Item(1).toString
            almacen(RowCounter) = tableresult.Rows.Item(RowCounter).Item(2).toString
            lot(RowCounter) = tableresult.Rows.Item(RowCounter).Item(3).toString
            cantidad(RowCounter) = tableresult.Rows.Item(RowCounter).Item(4).toString
            cantadiat(RowCounter) = tableresult.Rows.Item(RowCounter).Item(5).toString
            undad(RowCounter) = tableresult.Rows.Item(RowCounter).Item(6).toString
            Cantidadc(RowCounter) = tableresult.Rows.Item(RowCounter).Item(7).toString
            CantidadB(RowCounter) = tableresult.Rows.Item(RowCounter).Item(8).toString
            Session1(RowCounter) = tableresult.Rows.Item(RowCounter).Item(9).toString
            fecha(RowCounter) = tableresult.Rows.Item(RowCounter).Item(10).toString

            resultado(RowCounter) = GM.AsigDupla(Txtfecha.Text, cboPlanta0.SelectedValue, cboPlanta0.SelectedItem.Text, cboAlmacen.SelectedValue, cboAlmacen.SelectedItem.Text, mater(RowCounter), lot(RowCounter))

            RowCounter = RowCounter + 1
        Next



        'i = i + 1
        With lbError0
            .Visible = True
            .Text = resultado
        End With


    Catch ex As Exception
        lbError0.Text = ex.Message

    End Try

End If

End Sub

好的,这应该有效,但有些事我不明白你在我假设的文本框中显示结果。但这是诀窍。当我回答前一个帖子时,变量mater和lot是数组,你不能直接调用mater或lot。您必须指定数组的哪个项目。通过我做的修改,resultado是另一个数组,所以你不能直接调用它,你必须指定项目resultado()。

我需要更多信息,您将使用resultado做什么。

答案 1 :(得分:0)

For Each TableRow3 In tableresult3.Rows

                        mater3 = tableresult3.Rows.Item(RowCounter3).Item(0).ToString
                        lote3 = tableresult3.Rows.Item(RowCounter3).Item(1).ToString


                        Dim Con5 As New Data.SqlClient.SqlConnection
                        Dim StrSQL4 As String

                    Con5.ConnectionString = C.GetAppConfiguracion("Inventario", "ConnInventario")

                    StrSQL4 = "EXEC P_AsigDupla2 '" & Txtfecha.Text & "', '" & cboPlanta0.SelectedValue & "', '" & cboPlanta0.SelectedItem.Text & "', '" & cboAlmacen.SelectedValue & "', '" & cboAlmacen.SelectedItem.Text & "', '" & mater3 & "', '" & lote3 & "', '" & tbDupla.Text.ToUpper & "','" & estatus & "'"
                    Con5.Open()
                    Dim CmdAd As New Data.SqlClient.SqlCommand(StrSQL4, Con5)
                    CmdAd.ExecuteNonQuery()

                    Con5.Close()
                    RowCounter3 = RowCounter3 + 1