Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

My data is stored in an Access 2007 database. I have created a GUI which reads the data and the dates show in UK format. The GUI reads the database and put queried information into a datatable, the formats of the dates are in UK format. The user exports data from the datatable to Excel 2007 (works fine) where the dates show as UK format. I use the following code:
VB
'Export the Columns to excel file
For Each dc In datatableMain.Columns
    colIndex = colIndex + 1
    oSheet.Cells(1, colIndex) = dc.ColumnName
Next

'Export the rows to excel file
For Each dr In datatableMain.Rows
    rowIndex = rowIndex + 1
    colIndex = 0
    For Each dc In datatableMain.Columns
        colIndex = colIndex + 1
        oSheet.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
        'ProgressBar.PerformStep()
        Progresslbl.Text = "Total rows exported = " & rowIndex & " out of " & MaxRows2
        Me.Refresh()
    Next
Next

The export works fine and the output is exactly as expected. But when the form reloads on the GUI the dates have changed format from UK to USA format.

I have tried disposing of the datatable but this has no effect.

Any help would be greatly appreciated.


VB
For Each item As ListViewItem In DocumentedLst.SelectedItems
    Ref.Text = item.SubItems(0).Text
    fwords = Ref.Text.Split(New Char() {" "c})

    For Each row In myDataTable.Rows
        Dim tempvalue As String = ds.Tables("FullDetails").Rows(inc)("SMART").ToString()

        words = tempvalue.Split(New Char() {" "c})
        If words(0) = fwords(0) Then
            fwords = tempvalue.Split(New Char() {" "c})
            foundRow = row
        End If
        inc = inc + 1
    Next row

    If item.Selected = True Then
        Ref.Text = fwords(0)

        Retrieve.Visible = False
        Submit.Visible = True
        Delete.Visible = True

        If foundRow IsNot Nothing Then

            If Mid(fwords(1), 1, 2) = "IM" Then
                IM.Text = fwords(1)
                Server.Text = fwords(2)
            Else
                IM.Text = ""
                Server.Text = fwords(1)
            End If

            LocationName.Text = foundRow(3).ToString()
            StartTime.Text = foundRow(4).ToString() ****** This is displaying as USA format after the export has completed and the form is reloaded. If I exit the application and relaunch it shows correctly. The only only appears after the export. ******
Posted
Updated 5-Jun-14 6:33am
v2
Comments
Richard MacCutchan 5-Jun-14 12:01pm    
You need to show the code that is in error, no one can guess what you are doing to display these values.
p gosney 5-Jun-14 12:29pm    
For Each item As ListViewItem In DocumentedLst.SelectedItems
Ref.Text = item.SubItems(0).Text
fwords = Ref.Text.Split(New Char() {" "c})

For Each row In myDataTable.Rows
Dim tempvalue As String = ds.Tables("FullDetails").Rows(inc)("SMART").ToString()

words = tempvalue.Split(New Char() {" "c})
If words(0) = fwords(0) Then
fwords = tempvalue.Split(New Char() {" "c})
foundRow = row
End If
inc = inc + 1
Next row

If item.Selected = True Then
Ref.Text = fwords(0)

Retrieve.Visible = False
Submit.Visible = True
Delete.Visible = True

If foundRow IsNot Nothing Then

If Mid(fwords(1), 1, 2) = "IM" Then
IM.Text = fwords(1)
Server.Text = fwords(2)
Else
IM.Text = ""
Server.Text = fwords(1)
End If

LocationName.Text = foundRow(3).ToString()
StartTime.Text = foundRow(4).ToString() ****** This is displaying as USA format after the export has completed and the form is reloaded. If I exit the application and relaunch it shows correctly. The only only appears after the export. ******
Richard MacCutchan 5-Jun-14 12:35pm    
Something must be disturbing the locale setting. Add a format string when you display the date to ensure it shows in the correct format.
p gosney 5-Jun-14 12:41pm    
Thank you for the quick reply. Do you have a sample code? All attempts at this are failing at present.
Richard MacCutchan 5-Jun-14 13:09pm    
Sample code for what? You just need to add a format string in your ToString() call. You could always check the documentation if you're not sure.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900