Dear forum members,
i a m trying to export the contents of datagrid to excel but i am facing errors.After searching i have seen that the problems occurs because one of my columns is of type TIME and taht is why i am getting the error : Object reference not set to an instance of an object.
Is there a way to solve this problem withount havineg to mess up my database?

            For i = 1 To Me.DataGridView7.RowCount

                .cells(i, 1) = Me.DataGridView7.Rows(i - 1).Cells("name").Value.ToString 
                For j = 1 To DataGridView7.Columns.Count - 1
                    .cells(i, j + 1) = DataGridView7.Rows(i - 1).Cells(j).Value.ToString
                Next
            Next
            For j = 1 To DataGridView7.Columns.Count
                .columns(j).EntireColumn.AutoFit()
            Next
        End With

From your explanations, it appears that you have a column with the data type of TIME. I would suggest that you review the table structure (of that column) and specifically, check the default value for that column. Does that column have to be inserted with a record everytime? It seems to me that you are trying to read information in which nothing was stored in that "TIME" column.
As I said, check the default value.

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.