Below is a snippet with a simplified version of what is giving me trouble... The issue is that the date data is coming across formatted incorrectly.
I realize that I really need to make the PL/SQL take parameters and pass them but I am just trying to make it work first before I go bone up on PL/SQL as I am a T-SQL and VBA programmer first. So this foray into VB.net is a bit bumpy for me. I am lost trying to understand if the Excel data is coming across as a date or it is not and my attempts to format it are foolish. I did not see a way to determine the datatype of the column in a dataset. That's pretty much it, there are too many things I don't understand yet to figure out how to troubleshoot or fix this. Writing this, it occurs to me I could probably just adjust the format on the SQL side but I'd like to understand what fundamental I am missing other than Excel data is not strongly typed so many experiences are painful.
And the class I cobbled together from a few sites...
I realize that I really need to make the PL/SQL take parameters and pass them but I am just trying to make it work first before I go bone up on PL/SQL as I am a T-SQL and VBA programmer first. So this foray into VB.net is a bit bumpy for me. I am lost trying to understand if the Excel data is coming across as a date or it is not and my attempts to format it are foolish. I did not see a way to determine the datatype of the column in a dataset. That's pretty much it, there are too many things I don't understand yet to figure out how to troubleshoot or fix this. Writing this, it occurs to me I could probably just adjust the format on the SQL side but I'd like to understand what fundamental I am missing other than Excel data is not strongly typed so many experiences are painful.
Code:
Dim ds As DataSet = OExcelHandler.GetDataFromExcel(Session("Fullname"), lblStatus, Session("FileType"))
If ds IsNot Nothing Then
For Each dr As DataRow In ds.Tables(0).Rows
'There is an issue with the formatting of dr.Item("Request Date")... it is using a Euro dd/mm/yyyy format using tostring instead of the desired mm/dd/yyyy.
strSQL = "INSERT INTO SomeTable (Somefield)" & _
" VALUES (" & "to_date('" & [red]dr.Item("Request Date").Tostring()[/red] & "', 'mm/dd/yyyy') " & _
") "
Next
End if
And the class I cobbled together from a few sites...
Code:
Public Class ExcelHandler
' Return data in dataset from excel file. '
Public Function GetDataFromExcel(ByVal a_sFilepath As String, lbl As Label, strExtenstion As String) As DataSet
Dim ds As New DataSet()
Dim cn As OleDbConnection
Select Case strExtenstion
Case ".xls"
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & a_sFilepath & ";Extended Properties= Excel 8.0")
Case ".xlsx"
cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & a_sFilepath & ";Extended Properties= Excel 8.0")
End Select
Try
cn.Open()
Catch ex As OleDbException
Console.WriteLine(ex.Message)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
' It Represents Excel data table Schema.'
Dim dt As New System.Data.DataTable()
dt = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
If dt IsNot Nothing OrElse dt.Rows.Count > 0 Then
For sheet_count As Integer = 0 To dt.Rows.Count - 1
Try
' Create Query to get Data from sheet. '
Dim sheetname As String = dt.Rows(sheet_count)("table_name").ToString()
Dim da As New OleDbDataAdapter("SELECT * FROM [" & sheetname & "]", cn)
da.Fill(ds, sheetname)
Catch ex As DataException
lbl.Text = ex.Message
Catch ex As Exception
lbl.Text = ex.Message
End Try
Next
End If
cn.Close()
Return ds
End Function
End Class