Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime
Go Back  Xtreme Visual Basic Talk > > > Time in SQL database is MilitaryTime


Reply
 
Thread Tools Display Modes
  #1  
Old 04-14-2013, 04:42 PM
brendchc3 brendchc3 is offline
Newcomer
 
Join Date: Apr 2013
Posts: 7
Unhappy Time in SQL database is MilitaryTime


I have tried everything that I can think of to change the way the time shows in my database. I have gotten it so that it is the way I want it in my form, using h:mmtt as soon as it goes to the database, it is back to 24 hour format. I will post the code that I have and hopefully someone can tell me where Iam going wrong. I have the time set as time for the data type in sql.
Code:
Imports System.Data.SqlClient
Public Class ChildRollCall
    Dim connectionString As String = "Data Source=BRENDA-PC\SENIORPROJECT;Initial Catalog=DB_Daycare;Integrated Security=True"
    Dim cn As New SqlConnection(connectionString)
    Dim cmd As New SqlCommand
    Dim dr As SqlDataReader
     

    Private Sub ChildRollCall_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        dtpSignInOut.Format = DateTimePickerFormat.Custom
        dtpSignInOut.CustomFormat = "h:mm tt"
        dtpSignInOut.ShowUpDown = True
        

        Dim DB_DaycareDataSet As New DataSet
        Dim selectChildStatement As String = "Select * from Child"
        Dim ChildDataAdapter As New SqlDataAdapter(selectChildStatement, cn)
        ChildDataAdapter.Fill(DB_DaycareDataSet, "Child")
        Dim dr As DataRow
        For Each dr In DB_DaycareDataSet.Tables("Child").Rows
            LstBxChild.Items.Add(dr.Item("Name"))
            LstBxChild.Items.Add(dr.Item("ChildId"))
        Next dr
    End Sub

    Private Sub btnMainMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMainMenu.Click
        MainMenu.Show()
        Me.Hide()
    End Sub

    Private Sub btnSignIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSignIn.Click
        dtpSignInOut.CustomFormat = "h:mm tt"
        Format(dtpTodaysDate.Value, "yyyy/mm/dd")
        
        Try
            Dim ChildAdapter As New SqlDataAdapter("INSERT INTO RollCall  (SignIn, Date, ChildId) values ( '" & dtpSignInOut.Value & "', '" & dtpTodaysDate.Value & "', '" & LstBxChild.SelectedItem & "' )", cn)
            Dim DB_DaycareDataTable As New DataTable
            ChildAdapter.Fill(DB_DaycareDataTable)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Private Sub btnSignOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSignOut.Click

        Format(dtpSignInOut.Value, "h:mm tt")
        Format(dtpTodaysDate.Value, "yyyy/mm/dd")
        
        Try
            Dim RollCallAdapter As New SqlDataAdapter("UPDATE RollCall SET SignOut = '" & dtpSignInOut.Value & "'  WHERE ChildId = '" & LstBxChild.SelectedItem & "'", cn)
            Dim DB_DaycareDataTable As New DataTable
            RollCallAdapter.Fill(DB_DaycareDataTable)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Private Sub dtpSignInOut_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpSignInOut.ValueChanged

    End Sub

    
    Private Sub ListBoxParent_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBoxRollCall.SelectedIndexChanged

    End Sub

    Private Sub btnShowRecords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowRecords.Click
       
        Dim DB_DaycareDataSet As New DataSet
        Dim selectRollCallStatement As String = "Select * from RollCall"
        Dim RollCallDataAdapter As New SqlDataAdapter(selectRollCallStatement, cn)
        RollCallDataAdapter.Fill(DB_DaycareDataSet, "RollCall")
        ListBoxRollCall.Items.Clear()

        Dim dr As DataRow
        For Each dr In DB_DaycareDataSet.Tables("RollCall").Rows
            ListBoxRollCall.Items.Add(dr.Item("ChildId"))
            ListBoxRollCall.Items.Add(dr.Item("Date"))
            ListBoxRollCall.Items.Add(dr.Item("SignIn"))
            ListBoxRollCall.Items.Add(dr.Item("SignOut"))
            
        Next dr

    End Sub
End Class

Last edited by Flyguy; 04-15-2013 at 01:12 AM. Reason: Added [code][/code] tags and moved to .Net
Reply With Quote
  #2  
Old 04-15-2013, 02:19 AM
DrPunk's Avatar
DrPunkTime in SQL database is MilitaryTime DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

You can't change how the Time is written to the database. You change how the Time is displayed to the user.

Code:
Dim dr As DataRow
For Each dr In DB_DaycareDataSet.Tables("RollCall").Rows
    ListBoxRollCall.Items.Add(dr.Item("ChildId"))
    ListBoxRollCall.Items.Add(Format(dr.Item("Date"), "yyyy/mm/dd"))
    ListBoxRollCall.Items.Add(Format(dr.Item("SignIn"), "h:mm tt"))
    ListBoxRollCall.Items.Add(Format(dr.Item("SignOut"), "h:mm tt"))
           
Next dr
__________________
There are no computers in heaven!
Reply With Quote
  #3  
Old 04-15-2013, 09:08 AM
brendchc3 brendchc3 is offline
Newcomer
 
Join Date: Apr 2013
Posts: 7
Default

I tried what you said and this was the message that I received. (it seem to have worked for the date.
Unable to cast object of type 'System.TimeSpan' to type 'System.IConvertible'.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime
 
Time in SQL database is MilitaryTime
Time in SQL database is MilitaryTime
 
-->