Hello.
I have a button that the user selects to export the data to excel. I have 2 problems:
1) I am getting a major error on the export of the dataset to excel (once the user clicks 'Export')
Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
2) When I just put the connectionString name in from my webconfig file, I get an error, but when i put in the full connection string in, this error does not result:
"Format of the initialization string does not conform to specification starting at index 0."
Here is the sub (please excuse the length): I believe the error is a result of my dataset (of which I am using parameters).
================================================================================================
Protected Sub exportbyProgramButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exportbyProgramButton.Click
Try
Using connection As New SqlConnection("Server=corp290 ;Initial Catalog=testArena;User ID=simm; Password=$simeon$")
'Using connection As New SqlConnection("LiveCMSConnect")
connection.Open()
Dim selectPrograms As String = "select * from Exploitation_view where ID = @ID"
Dim adapter As SqlDataAdapter = New SqlDataAdapter
Dim selectCMD As SqlCommand = New SqlCommand(selectPrograms, connection)
adapter.SelectCommand = selectCMD
'add parameters
selectCMD.Parameters.Add("@ID", SqlDbType.Int).Value = programList.SelectedValue
Dim ds As DataSet = New DataSet
adapter.Fill(ds, "Harbour_View")
'begin to specify excel worksheet details
Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oCells As Excel.Range
Dim strFileName = "ViewByProgram.xls"
'start excel and get application object
oExcel = CreateObject("Excel.Application")
'get a workbook
oBook = oExcel.Workbooks.Add
oSheet = oBook.ActiveSheet(1)
oBook.ActiveSheet(1).Name = "Program Listing"
oCells = oSheet.Cells
'define styles
With oSheet.Range("A1", "H1")
.Font.Bold = True
.Font.FontStyle.Equals("Arial")
End With
'Add the table headers
oSheet.Range("A1").Value = "Record ID"
oSheet.Range("B1").Value = "Program"
oSheet.Range("C1").Value = "Platform Type"
oSheet.Range("D1").Value = "Rights"
oSheet.Range("E1").Value = "OptionType"
oSheet.Range("F1").Value = "Comments"
oSheet.Range("G1").Value = "Estimated Cost Range"
oSheet.Range("H1").Value = "Date Option expires"
Dim iRows, intColumnValue As Integer
Dim xyz = ds.Tables("Harbour_View")
For iRows = 2 To xyz.rows.Count - 1
For intColumnValue = 0 To xyz.Columns.Count - 1
oCells(iRows + 1, intColumnValue + 1).value = xyz.Rows(iRows).ItemArray(intColumnValue).ToString
Next
Next
oExcel.Visible = False
oExcel.DisplayAlerts = False
oBook.SaveAs(strFileName)
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
outputPanel.Visible = True
outputPanel.Text = "<br>Thank you. Your selected data based on 'Program Name' has been saved as TestSatelite.xls"
ExportbyDates.Visible = False
startDate.Text = ""
endDate.Text = ""
connection.Close()
End Using
Catch ex As Exception
outputPanel.Visible = True
outputPanel.Text = "Error:<br>" & ex.Message.ToString
End Try
End Sub
I have a button that the user selects to export the data to excel. I have 2 problems:
1) I am getting a major error on the export of the dataset to excel (once the user clicks 'Export')
Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
2) When I just put the connectionString name in from my webconfig file, I get an error, but when i put in the full connection string in, this error does not result:
"Format of the initialization string does not conform to specification starting at index 0."
Here is the sub (please excuse the length): I believe the error is a result of my dataset (of which I am using parameters).
================================================================================================
Protected Sub exportbyProgramButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exportbyProgramButton.Click
Try
Using connection As New SqlConnection("Server=corp290 ;Initial Catalog=testArena;User ID=simm; Password=$simeon$")
'Using connection As New SqlConnection("LiveCMSConnect")
connection.Open()
Dim selectPrograms As String = "select * from Exploitation_view where ID = @ID"
Dim adapter As SqlDataAdapter = New SqlDataAdapter
Dim selectCMD As SqlCommand = New SqlCommand(selectPrograms, connection)
adapter.SelectCommand = selectCMD
'add parameters
selectCMD.Parameters.Add("@ID", SqlDbType.Int).Value = programList.SelectedValue
Dim ds As DataSet = New DataSet
adapter.Fill(ds, "Harbour_View")
'begin to specify excel worksheet details
Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oCells As Excel.Range
Dim strFileName = "ViewByProgram.xls"
'start excel and get application object
oExcel = CreateObject("Excel.Application")
'get a workbook
oBook = oExcel.Workbooks.Add
oSheet = oBook.ActiveSheet(1)
oBook.ActiveSheet(1).Name = "Program Listing"
oCells = oSheet.Cells
'define styles
With oSheet.Range("A1", "H1")
.Font.Bold = True
.Font.FontStyle.Equals("Arial")
End With
'Add the table headers
oSheet.Range("A1").Value = "Record ID"
oSheet.Range("B1").Value = "Program"
oSheet.Range("C1").Value = "Platform Type"
oSheet.Range("D1").Value = "Rights"
oSheet.Range("E1").Value = "OptionType"
oSheet.Range("F1").Value = "Comments"
oSheet.Range("G1").Value = "Estimated Cost Range"
oSheet.Range("H1").Value = "Date Option expires"
Dim iRows, intColumnValue As Integer
Dim xyz = ds.Tables("Harbour_View")
For iRows = 2 To xyz.rows.Count - 1
For intColumnValue = 0 To xyz.Columns.Count - 1
oCells(iRows + 1, intColumnValue + 1).value = xyz.Rows(iRows).ItemArray(intColumnValue).ToString
Next
Next
oExcel.Visible = False
oExcel.DisplayAlerts = False
oBook.SaveAs(strFileName)
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
outputPanel.Visible = True
outputPanel.Text = "<br>Thank you. Your selected data based on 'Program Name' has been saved as TestSatelite.xls"
ExportbyDates.Visible = False
startDate.Text = ""
endDate.Text = ""
connection.Close()
End Using
Catch ex As Exception
outputPanel.Visible = True
outputPanel.Text = "Error:<br>" & ex.Message.ToString
End Try
End Sub