Solved

ASP.net and Access Date

Posted on 2011-03-23
3
273 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
Comment Utility
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
Comment Utility
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
Comment Utility
worked like a charm. Thanks very much
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now