I am working with Visual studio 2003.
Have data grid , data adapter and dataset and an access data base
In access database the one field "time" is defined as date/time and format as medium date.
This field stores the time properly i.e. 3.00PM
But when i load the datagrid, datagrid loads fine but in time column values appears as 11-1-2010 3.00PM i.e "General Date"

How can I load my datagrid with value showing 3.00PM format.
Yasho

Hi!

Create a "DataGridViewCellStyle" object and set its "format" according to your need:

Dim style As New DataGridViewCellStyle()
        style.Format = "dd-MM-yyyy"
        DataGridView1.Columns("Date").DefaultCellStyle = style

A simple demo: (change connectionstring, cmdtext to make this sample working)

Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\db1.mdb" & ";")
        Dim cmd As New OleDb.OleDbCommand("Select * from tblStd")
        cmd.Connection = con
        Dim dt As New DataTable
        Dim d As New OleDb.OleDbDataAdapter(cmd)
        d.Fill(dt)
        DataGridView1.DataSource = dt
        Dim style As New DataGridViewCellStyle()
        style.Format = "dd-MM-yyyy"
        DataGridView1.Columns("Date").DefaultCellStyle = style

Hope it helps.

Edited 5 Years Ago by ShahanDev: n/a

This article has been dead for over six months. Start a new discussion instead.