Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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()
Reply With Quote
  #2 (permalink)  
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.
Reply With Quote
  #3 (permalink)  
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
Reply With Quote
  #4 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:27 AM.


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