Subject: Format Date to time field
Posted By: KennethMungwira Post Date: 11/13/2003 10:03:33 AM
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 By: bmains Reply Date: 11/14/2003 8:56:05 AM
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 By: sal Reply Date: 11/14/2003 9:34:45 AM
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 By: KennethMungwira Reply Date: 11/17/2003 10:48:48 AM
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

Go to topic 6525

Return to index page 1004
Return to index page 1003
Return to index page 1002
Return to index page 1001
Return to index page 1000
Return to index page 999
Return to index page 998
Return to index page 997
Return to index page 996
Return to index page 995