Solved

ASP.net and Access Date

Posted on 2011-03-23
3
317 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 41

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:Murray Brown
ID: 35199666
worked like a charm. Thanks very much
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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 …

690 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