Results 1 to 5 of 5

Thread: [2005] DateTime Bindings DateTimePickers

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    Smile [2005] DateTime Bindings DateTimePickers

    I want to update the date and time from two separate pickers to my table.

    My 2 DTPers are bound to a dataset.

    One is in the Short Format, the other is Time.

    I have several other bound controls, and I just do a .Update to update my table. I tried just updating the row:
    Code:
    Me.DsTradeShow1.Tables("Tradeshow_Details").Rows(0).Item("Show_Date") = CDate(Me.DateTimePicker15.Text & " " & Me.DateTimePicker16.Text)
    but it throws an exception when I do my save.

    Any help would be appreciated!
    Tuber

    "I don't know the rules"

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: [2005] DateTime Bindings DateTimePickers

    Please provide details on the exception raised.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    Re: [2005] DateTime Bindings DateTimePickers

    Code:
    An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll
    
    Additional information: DataTable internal index is corrupted: '5'.
    Tuber

    "I don't know the rules"

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] DateTime Bindings DateTimePickers

    First up, if you're manually moving the data from the controls to the DataTable then there's no binding going on. The whole point of binding is so you do NOT have to write your own code to move the data.

    As for the code you do have, don't ever use strings to manipulate dates if it can be avoided. Your DataTimePickers already contain DateTime values and you want a DateTime value so there is no reason at all for using strings anywhere in the equation.

    Also, please use descriptive names for all variables. "DateTimePicker15" and "DateTimePicker16" mean nothing to anyone.
    vb.net Code:
    1. Me.DsTradeShow1.Tables("Tradeshow_Details").Rows(0).Item("Show_Date") = Me.datePicker.Value.Date.Add(Me.timePicker.Value.TimeOfDay)
    That code gets the DateTime from the date picker, zeroes the time and then adds the TimeSpan from the time picker.
    Last edited by jmcilhinney; Jan 26th, 2009 at 07:52 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    Re: [2005] DateTime Bindings DateTimePickers

    Well I don't want to manually move the data. I want them to be bound. I do not want to in code fill the data to my date time pickers.

    I just don't know how to get both the date and the time to be bound to the same table field and still save correctly.

    Here is my save procedure:

    Code:
      Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
    
            Dim BindingManager As BindingManagerBase = Me.BindingContext(Me.DsTradeShow1, "Tradeshow_Details")
            BindingManager.EndCurrentEdit()
    
            If Not Me.GetConnection Then Exit Sub
    
            Try
                Me.sdaShowDetails.Update(Me.DsTradeShow1, "Tradeshow_Details")
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                Me.SqlConnection1.Close()
    
            End Try
    
            Me.Panel2.SendToBack()
        End Sub
    And it errors out when I end the current edit:

    Code:
            Dim BindingManager As BindingManagerBase = Me.BindingContext(Me.DsTradeShow1, "Tradeshow_Details")
            BindingManager.EndCurrentEdit()
    I just want to know how to Bind 2 date time pickers to the same field. One for the date, the other for the time and get them to save correctly.
    Tuber

    "I don't know the rules"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width