|
-
Jan 26th, 2009, 03:39 PM
#1
Thread Starter
Hyperactive Member
[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"
-
Jan 26th, 2009, 03:50 PM
#2
Re: [2005] DateTime Bindings DateTimePickers
Please provide details on the exception raised.
-
Jan 26th, 2009, 05:15 PM
#3
Thread Starter
Hyperactive Member
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"
-
Jan 26th, 2009, 07:29 PM
#4
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:
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.
-
Jan 27th, 2009, 09:47 AM
#5
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|