I am trying to fill an excel sheet from SQL Server database and getting a message with code
HRESULT: 0x800401A8
Please assist me.
Dim file As String = "C:\Techform.xlsx"
Dim xlApp_2 As New Excel.Application
xlApp_2.Visible = False
xlApp_2.DisplayAlerts = False
Dim oBook As Excel.Workbook
oBook = xlApp_2.Workbooks.Open(file)
Dim oSheet As Excel.Worksheet
oSheet = oBook.Worksheets(1)
objConnection.Open()
adapter_view.SelectCommand = New SqlCommand()
adapter_view.SelectCommand.Connection = objConnection
adapter_view.SelectCommand.CommandText = "SELECT * FROM TECHNICAL_AMS_CALC_GARGANTUA "
adapter_view.SelectCommand.CommandType = CommandType.Text
adapter_view.Fill(dataset, "GARGANTUA_AVERAGE_Data")
dataTable_CALC = dataset.Tables("GARGANTUA_AVERAGE_Data")
adapter_view.Dispose()
For h As Integer = 0 To dataTable_CALC.Rows.Count - 1
SoG_AVG = dataTable_CALC.Rows(h).Item("VPM_SPEED_THROUGH_WATER_AVG")
oSheet.Range("E3").Value = dataTable_CALC.Rows(h).Item("VPM_SPEED_THROUGH_WATER_AVG")
oSheet.Range("F3").Value = dataTable_CALC.Rows(h).Item("VPM_SPEED_THROUGH_WATER_MAX")
oBook.SaveAs(file + " " + dataTable_CALC.Rows(h).Item("ACTION_DATE") + ".xlsx", CreateBackup:=False)
oBook.Close()
xlApp_2.Quit()
Next
Like this:
Dim file As String = "C:\Techform.xlsx"
Dim xlApp_2 As New Excel.Application
xlApp_2.Visible = False
xlApp_2.DisplayAlerts = False
Dim oBook As Excel.Workbook
oBook = xlApp_2.Workbooks.Open(file)
Dim oSheet As Excel.Worksheet
oSheet = oBook.Worksheets(1)
objConnection.Open()
adapter_view.SelectCommand = New SqlCommand()
adapter_view.SelectCommand.Connection = objConnection
adapter_view.SelectCommand.CommandText = "SELECT * FROM TECHNICAL_AMS_CALC_GARGANTUA "
adapter_view.SelectCommand.CommandType = CommandType.Text
adapter_view.Fill(dataset, "GARGANTUA_AVERAGE_Data")
dataTable_CALC = dataset.Tables("GARGANTUA_AVERAGE_Data")
adapter_view.Dispose()
For h As Integer = 0 To dataTable_CALC.Rows.Count - 1
SoG_AVG = dataTable_CALC.Rows(h).Item("VPM_SPEED_THROUGH_WATER_AVG")
oSheet.Range("E3").Value = dataTable_CALC.Rows(h).Item("VPM_SPEED_THROUGH_WATER_AVG")
oSheet.Range("F3").Value = dataTable_CALC.Rows(h).Item("VPM_SPEED_THROUGH_WATER_MAX")
Next
oBook.SaveAs(file + " " + dataTable_CALC.Rows(h).Item("ACTION_DATE") + ".xlsx", CreateBackup:=False)
oBook.Close()
xlApp_2.Quit()
User contributions licensed under CC BY-SA 3.0