Home All Groups Group Topic Archive Search About

Convert UTC time to localtime in SqlDataAdapter

Author
2 Mar 2006 1:43 PM
kms
I have the following method, that retrieves data from a SQL server and
propergates the data in a datagrid. No problems there:
________________________________________________________________

Public Sub fetchBillPostings(ByVal stationName As String, ByRef
BillpostingsDG As DataGrid)
        Dim dataadapter As New SqlDataAdapter( _
        "SELECT dbo.Postings.[Time], dbo.Postings.Locator,
dbo.Postings.PriceGroup, " & _
        "dbo.Postings.License, dbo.Postings.Price,
dbo.Postings.Currency " & _
        "FROM dbo.Postings INNER JOIN dbo.Rooms ON dbo.Postings.Room =
dbo.Rooms.Name " & _
        "INNER JOIN dbo.Stations ON dbo.Rooms.Id = dbo.Stations.Room "
& _
        "WHERE (dbo.Stations.Name = '" & stationName & "')", sqlConn)

        Dim dataset = New DataSet("Testdataset")
        dataadapter.Fill(dataset, "Postings")
        BillpostingsDG.SetDataBinding(dataset, "Postings")

        ' Formater datagrid korrekt


        Dim ts1 As DataGridTableStyle
        ts1 = New DataGridTableStyle
        ts1.MappingName = "Postings"
        ts1.GridLineColor = Color.White
        ts1.HeaderBackColor = Color.FromArgb(62, 98, 144)
        ts1.HeaderForeColor = Color.White
        ts1.SelectionBackColor = Color.FromArgb(82, 118, 164)

        If Not BillpostingsDG.TableStyles.Contains(ts1.MappingName)
Then
            BillpostingsDG.TableStyles.Add(ts1)
            BillpostingsDG.TableStyles.Add( _

ExtendedDataGrid.DataGridApplyAutomaticWidths(BillpostingsDG,
BillpostingsDG.TableStyles(0), 10, 200))

            'formater sådan at datoen også indeholder tid
            Dim dgtbc As DataGridTextBoxColumn =
BillpostingsDG.TableStyles.Item(1).GridColumnStyles.Item(0)
            dgtbc.Format = "g"
            dgtbc.FormatInfo = New
System.Globalization.CultureInfo(&H413)  ' holland

            'søg for at null bliver til blank:
            dgtbc =
BillpostingsDG.TableStyles.Item(1).GridColumnStyles.Item(1)
            dgtbc.NullText = ""

            dgtbc =
BillpostingsDG.TableStyles.Item(1).GridColumnStyles.Item(2)
            dgtbc.NullText = ""

        End If

    End Sub
________________________________________________________________

Now the problem is that that the time stored in dbo.Postings.[Time] is
in UTC and I would like to display it with localtime (in my case +1
hour)

How can I do that? As far as I can see there is something in .net 2.0
that enables you to change the datetime format in the dataset. But
thats not an option here. Also note that I only need to display the
data. I'm not changing anything in the datagrid and updating the SQL
data.

Thanks in advance for any input.

AddThis Social Bookmark Button