0

i have used below code in vb.net project in same project 1 - 2 forms is working but 1 form not work following erorr not converted datatable to datatable() please anybody lookin and help. Thanks in advance.

Severity Code Description Project Path File Line Suppression State Error BC30311 Value of type 'DataTable' cannot be converted to 'DataTable()'.504 N/A

functioncode as below.

Private Sub btnSDEANew_Click(sender As Object, e As EventArgs) Handles btnSDEANew.Click

    Dim dt As New DataTable
    Dim spath, scsvpath As String

    Dim strSCPath = GetSettings("ExportInwardFilePath") & "\AXIX_" & GetSettings("CustName") & "\" & Format(dtp_ChDate.Value, "ddMMyyyy").ToString() 'GetSettings("ExportOutwardBankFile")

    scsvpath = strSCPath + "\"
    For i = 1 To cBatchDetails.Rows.Count - 1
        spath = strSCPath + "\" + "ITEMS_" + Format(dtp_ChDate.Value, "yyyyMMdd") + "_" + Format(Val(cBatchDetails.Item(i, "BatchID").ToString()), "00000") + "\"

        DT.Columns.Add("C1", GetType(String))
        DT.Columns.Add("C2", GetType(String))
        DT.Columns.Add("C3", GetType(String))
        DT.Columns.Add("C4", GetType(String))
        DT.Columns.Add("C5", GetType(String))
        DT.Columns.Add("C6", GetType(String))
        DT.Columns.Add("C7", GetType(String))
        DT.Columns.Add("C8", GetType(String))

        Dim msiD As Integer

        Dim _CTSinstruments = GetBatchDetails(cBatchDetails.Item(i, "BatchID"))

        msiD = 1
        For Each DR In _CTSinstruments
            If msiD = 1 Then
                DT.Rows.Add("004", "225", Now.ToString("ddMMyyyy"), DR.NoOfChqs, DR.SlipAmount, "LICHO", "LCC", "0")
                msiD = msiD + 1
                Exit For
            End If
        Next

        Dim x1 As New Int64
        x1 = 10400201001
        Dim x As String

        x = Now.ToString("ddMMyyyy") + "400211002" + Format(x1, "0000000000000") + "0004"
        For Each dr In _CTSinstruments
            DT.Rows.Add(x, Format(dr.ChqNo, "000000"), Now.ToString("ddMMyyyy"), Format(Val(dr.MICR3), "00"), Format(Val(Mid(dr.MICR1, 1, 3)), "000"), Format(Val(Mid(dr.MICR1, 4, 3)), "000"), Format(Val(Mid(dr.MICR1, 7, 3)), "000"), dr.ChqAmount)

        Next
        DatatablesToExcel(dt, spath, "data.xlsx")
        Exit For

    Next

End Sub

1 Answer 1

1

The error message is telling you that you are providing a single DataTable where a DataTable array is expected. That's what DataTable() is: an array of DataTable. Given that the name of the method you're calling - DatatablesToExcel - implies multiple DataTables, that first parameter is presumably type DataTable(). If you only have one, you need to put that one in an array:

DatatablesToExcel({dt}, spath, "data.xlsx")

That's basically shorthand for this:

DatatablesToExcel(New DataTable() {dt}, spath, "data.xlsx")

i.e. it creates a new array with that one element.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.