Results 1 to 3 of 3

Thread: dd-MM-yyyy format in datagrid

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Malaysia
    Posts
    124

    dd-MM-yyyy format in datagrid

    Hi, all
    I retrieved the date from the Access database, the date format was MM-dd-yyyy which displayed in Datagrid, but how do I convert to dd-MM-yyyy in Datagrid?


    Thanks!

  2. #2
    Member
    Join Date
    Jul 2003
    Posts
    41
    Dim strSQL As String
    strSQL = "SELECT CAST(READINGS.READING_TIMESTAMP AS DATETIME) AS 'Time Stamp', "
    strSQL += "READINGS.reading_value * tblMeterType.meter_multiplier AS 'Value' "
    strSQL += "FROM READINGS INNER JOIN (tblMeters INNER JOIN tblMeterType ON tblMeters.meter_type_counter = tblMeterType.meter_type_counter) ON READINGS.meter_counter = tblMeters.meter_counter "
    Dim data_Dataset As New DataSet
    Dim data_adapter As OdbcDataAdapter
    Dim myConnectString As String = MyConString

    ' Create the SqlDataAdapter.
    data_adapter = New OdbcDataAdapter(strSQL, myConnectString)
    Try
    Cursor.Current = Cursors.WaitCursor
    ' Map Table to Contacts.
    Me.dataGridList.TableStyles.Clear()
    data_adapter.TableMappings.Add("Table", "Contacts")

    ' Fill the DataSet.
    data_adapter.Fill(data_Dataset)

    ' Bind the DataGrid control to the Contacts DataTable.
    Me.dataGridList.DataSource = data_Dataset.Tables("Contacts")

    Dim DGTextColTime As New DataGridTextBoxColumn
    With DGTextColTime
    .MappingName = "TIME STAMP"
    .HeaderText = "Time Stamp"
    .Format = "MM/dd/yyyy HH:mm:ss"
    .Width = 125
    .ReadOnly = True
    End With

    Dim DGTextColVal As New DataGridTextBoxColumn
    With DGTextColVal
    .MappingName = "VALUE"
    .HeaderText = "Value"
    .ReadOnly = True
    End With

    Dim oTblStyle As New DataGridTableStyle
    oTblStyle.MappingName = "Contacts"

    Dim oGridColStyles As GridColumnStylesCollection
    oGridColStyles = oTblStyle.GridColumnStyles
    oGridColStyles.Add(DGTextColTime)
    oGridColStyles.Add(DGTextColVal)

    dataGridList.TableStyles.Add(oTblStyle)

    Dim numRows As Integer = dataGridList.BindingContext(dataGridList.DataSource, _
    dataGridList.DataMember).Count
    Me.dataGridList.CaptionText = numRows & " records."


    Hope this example can help you.

    ANG

  3. #3
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    What about the CONVERT() method in sql? I sue that to fix dates. Or perhaps that only works in sql server... I don't know much access...


    kind regards
    Henrik

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width