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,

You can find some information about Dates and Time formats here.

Please Show us your coding then we will be able to help you

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.