Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
| Search | Today's Posts | Mark Forums Read
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 13th, 2003, 11:03 AM
Authorized User
 
Join Date: Jun 2003
Location: Birmingham, N/a, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default Format Date to time field

How do I format a field from Access Database which is placed in a Datafield. The result of my Dataset fill returns a full date, for the 'StartTime' and 'EndTime' when all I want is the time? * Please note that in Access I have the field properties shown correctly..

Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\DATA\ACCESS\NameDatabase"
            Dim strSQL As String = "SELECT [ItemName], [StartDate],[Requests].[StartTime],[EndDate],[EndTime],[Name] FROM(Requests) "
            strSQL = strSQL & "WHERE (([ItemName]= '" & nItem & "')"
            strSQL = strSQL & "AND (([StartDate])"
            strSQL = strSQL & "BETWEEN #" & kStart & "#"
            strSQL = strSQL & "AND #" & kStop & "#));"

            Dim conn As OleDbConnection = New OleDbConnection(conStr)
            conn.Open()
            Dim da As OleDbDataAdapter = New OleDbDataAdapter(strSQL, conn)

            Dim ds As DataSet = New DataSet()
            da.Fill(ds, "Requests")
            Dim dv As DataView = ds.Tables("Requests").DefaultView
            DataGrid1.DataSource = dv
            conn.Close()
 
Old November 14th, 2003, 09:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Maybe you want to store the date and time separately in the database and store it as a text field? This way, you wouldn't have to do any parsing. Otherwise, you may want to check out the DateTime object, to see if you can parse it out.
 
Old November 14th, 2003, 10:34 AM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Location: Clarksville, TN, USA.
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do not store it as a text field. It is a time for a reason. You can change the format inside the table to long time or short time.

Just imagine trying to sort by this "Time" field when it is a text field.



Sal
 
Old November 17th, 2003, 11:48 AM
Authorized User
 
Join Date: Jun 2003
Location: Birmingham, N/a, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, Thank you

When I return the Time field to my Datagrid it shows as a date 1700's or something like that. Why would it do this??

Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\DATA\ACCESS\13FloorEquipment.mdb"
            Dim strSQL As String = "SELECT [ItemName], [StartDate],[Requests].[StartTime],[EndDate],[EndTime],[Name] FROM(Requests) "
            strSQL = strSQL & "WHERE (([ItemName]= '" & nItem & "')"
            strSQL = strSQL & "AND (([StartDate])"
            strSQL = strSQL & "BETWEEN #" & kStart & "#"
            strSQL = strSQL & "AND #" & kStop & "#));"
            MsgBox(strSQL)

            Dim conn As OleDbConnection = New OleDbConnection(conStr)
            conn.Open()
            Dim da As OleDbDataAdapter = New OleDbDataAdapter(strSQL, conn)

            Dim ds As DataSet = New DataSet()
            da.Fill(ds, "Requests")
            Dim dv As DataView = ds.Tables("Requests").DefaultView
            DataGrid1.DataSource = dv

            conn.Close()
                    End If

*********************************
I was think that maybe there is something wrong with my fill object...

PLease Help




Similar Threads
Thread Thread Starter Forum Replies Last Post
date time format vb certified Pro VB 6 4 December 18th, 2009 08:16 AM
Behavior of Date/Time Format Differs When Accessed Oliver Dempsey Classic ASP Basics 25 May 2nd, 2005 01:24 AM
Null Value for Date/Time Field ksegars4 Crystal Reports 2 November 17th, 2004 11:58 AM
Format Date Time ganesh15 PHP How-To 2 August 20th, 2003 05:26 AM
How to format a Date field Niaz SQL Server 2000 2 June 25th, 2003 12:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.