i am trying to import data from excel to datagrid view. why instead of actuel data "System.__ComObject" is displayed in datagrid cell.

 Dim xl As New excel.Application
            Dim xlsheet As excel.Worksheet
            Dim xlwbook As excel.Workbook

            xlwbook = xl.Workbooks.Open("d:\PayableInput\InvoiceUpload.xlsx")
            xlsheet = xlwbook.Sheets.Item(1)
            Dim Rowst As Integer = 0
            Dim RN As Integer = 1
            DgvInvoiceDetails.Rows.Clear()

            RN = 1

            Dim N As Integer = 0

            For N = 1 To 5
                DgvInvoiceDetails.Rows.Add()
                DgvInvoiceDetails.Item(0, N).Value = xlsheet.Cells(N, 1)

            Next



            xl.ActiveWorkbook.Close(False, "d:\PayableInput\InvoiceUpload.xlsx")
            xl.Quit()
            xlwbook = Nothing
            xl = Nothing



        thanks

Did you try DgvInvoiceDetails.Item(0, N).Value = xlsheet.Cells(N, 1).Value; ? Also have a look at this

Use the following code to add the rows and fill the data at the same time, this shall solve the problem:

For N = 1 To 5
DgvInvoiceDetails.Rows.Add(xlsheet.Cells(N, 1).value)
Next

thanks

Both the suggestions were useful

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.