Solved

ASP.net and Access Date

Posted on 2011-03-23
3
308 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
[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:murbro
ID: 35199666
worked like a charm. Thanks very much
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Differences Between Access 2013 Runtime and 2013 Full Version? 33 69
Access Database 5 47
microsoft Accesss Basic Coding 44 67
Problem to copy file 14 53
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

726 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