DeepBlueZen
asked on
How to call stored proc from a change to a date in datagridview
Ok, here's a bit of an odd situation. I have a datagridview which contains all sorts of information relating to investment bonds. When a bond is intiially created, I populate a table with the bond ID and the dates on which it'll pay interest. so far so good.
In my datagridview, I want the user to be able to correct errors made when the bond was first input. If they change the interest payment frequency or maturity date, I want to fire two stored procs. one which deletes the entries for the interest payment dates and the other to recreate these entries with the correct data. both these stored procedures work just fine.
The problem is a) how do i detect that a specified field in the datagridview has changed and b) how do I retrieve the new value the user has entered into the datagridview. (I'll need to pass the new values into my stored procs as input parameters)
Thanks
In my datagridview, I want the user to be able to correct errors made when the bond was first input. If they change the interest payment frequency or maturity date, I want to fire two stored procs. one which deletes the entries for the interest payment dates and the other to recreate these entries with the correct data. both these stored procedures work just fine.
The problem is a) how do i detect that a specified field in the datagridview has changed and b) how do I retrieve the new value the user has entered into the datagridview. (I'll need to pass the new values into my stored procs as input parameters)
Thanks
ASKER
I'm using windows forms.
Really, I want to compare old value against new value on the save event of the binding navigator, so I guess what I need is how to access the original and new values. I'm trying to avoid deleteing and creating data in a child table until the user actually commits the change. If he edits a value, and then edits it again and changes his mind one more time, rebuilding the interest date entries after every edit probably adds too much overhead. I'd rather validate his (her) input on cell change, but not delete and recreate any interest date entires until they actually commit the change.
Thanks for the link though
Really, I want to compare old value against new value on the save event of the binding navigator, so I guess what I need is how to access the original and new values. I'm trying to avoid deleteing and creating data in a child table until the user actually commits the change. If he edits a value, and then edits it again and changes his mind one more time, rebuilding the interest date entries after every edit probably adds too much overhead. I'd rather validate his (her) input on cell change, but not delete and recreate any interest date entires until they actually commit the change.
Thanks for the link though
Then you can use CellValidating event
Private Sub DataGridView1_CellValidati ng(ByVal sender As Object, ByVal e
As System.Windows.Forms.DataG ridViewCel lValidatin gEve ntArgs) Handles DataGridView1.CellValidati ng
Dim strOld As String = DataGridView1.Item(e.Colum nIndex, e.RowIndex).Value.ToString
Dim strNew As String = e.FormattedValue.ToString
Trace.WriteLine(String.For mat("Old Value {0} {1}New Value {2}",
strOld, ControlChars.NewLine, strNew))
End Sub
Private Sub DataGridView1_CellValidati
As System.Windows.Forms.DataG
Dim strOld As String = DataGridView1.Item(e.Colum
Dim strNew As String = e.FormattedValue.ToString
Trace.WriteLine(String.For
strOld, ControlChars.NewLine, strNew))
End Sub
ASKER
Hello CaptainHarlock
Great answer, but I'm trying to perform this check on the binding navigator save event, not at the cell validating event. Essentially, I don't want to call stored procedures against my underlying data until the user actually and finally commits the change by saving. It might still be possible to retreive the old and new values using your code fragment though. I'll give it a go and let you know how I get on.
Thanks
Great answer, but I'm trying to perform this check on the binding navigator save event, not at the cell validating event. Essentially, I don't want to call stored procedures against my underlying data until the user actually and finally commits the change by saving. It might still be possible to retreive the old and new values using your code fragment though. I'll give it a go and let you know how I get on.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you. That's essentially what I did.
Are you using ASP.Net or WindowsForms?
You have CellValueChange event fired when the value of a cell changes.
Take a look to this:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged.aspx