Solved

ASP.net and Access Date

Posted on 2011-03-23
3
301 Views
Last Modified: 2012-05-11
Hi

Using the code below in my ASP.net code I populate a DropDownList with data from
an Access field that is formatted as short date. My problem is that it includes the time at noon.
How do I get rid of the time and only show the date?
Sub LoadStartDateDropDown()
        '// define a connection to the database
        Dim cs As String = ConfigurationManager.ConnectionStrings("WhatEverNameYouWant").ConnectionString
        cs = cs.Replace("App_Data\GC.accdb", Server.MapPath("App_Data\GC.accdb"))

        Dim cn As New OleDbConnection(cs)
        Try
            '// define the sql statement to execute
            Dim cmd As New OleDbCommand("SELECT DISTINCT [Start date] FROM [Table1]", cn)
            '// open the connection
            cn.Open()
            '// execute the sql statement
            Using reader As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
                DropDownList_StartDate.DataSource = reader
                DropDownList_StartDate.DataValueField = "Start date"
                DropDownList_StartDate.DataTextField = "Start date"
                DropDownList_StartDate.DataBind()
            End Using
        Catch ex As Exception
            Response.Write(ex.Message)

        Finally
            If cn.State <> ConnectionState.Closed Then
                cn.Close()
            End If
        End Try
    End Sub

Open in new window

0
Comment
Question by:murbro
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 35199076
You can use the DataTextFormatString property to control that:
DropDownList_StartDate.DataTextFormatString = "{0:dd/MM/yyyy}"

Open in new window

0
 
LVL 40

Expert Comment

by:Sharath
ID: 35199417
try DATEVALUE.
Dim cmd As New OleDbCommand("SELECT DISTINCT DATEVALUE([Start date]) FROM [Table1]", cn)

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 35199666
worked like a charm. Thanks very much
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question