K
Kevin Jackson
I'm using an Access Database, and VB.Net 2003.
One of my tables has, amongst others, 2 fields that are defined as
Date/Time fields. with a format of Medium Date.
In the VB Solution explorer I added a new form using the Data Form Wizard
over this table. This creates the appropriate Bound fields on the form
linked to the fields in the database.
The problem I've run into is, when I have put dates into these fields and
then add the record to the database, I sometimes have a need to clear those
dates and update the record with no date . but When I do, After pressing
the Update button, the date re-appears in the field. It hasn't been removed
from the database record..
Here is the code thath is responsible for doing the update. This code is all
generated by the form wizard.
I have also tried creating a simple test application in a completely
seperate directory with its own Db, that has one field in the table defined
as a date/time field.
In the Db the properties of the date field are: Format - Medium Date,
Required = No, and Indexed = No. Those are the only propertiies set.
When I say I'm blanking out the field on the VB Form I have tried multiple
things. Setting it to Zero, Setting it to Nothing, I'm not sure how to set
it to Null, maybe that's my problem ?
--------------------------------------------------------------------------
' Update Button
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Try
'Attempt to update the datasource.
Me.UpdateDataSet()
Catch eUpdate As System.Exception
'Add your error handling code here.
'Display error message, if any.
System.Windows.Forms.MessageBox.Show(eUpdate.Message)
End Try
Me.objtrial2ds_PositionChanged()
End Sub
----------------------------------------------------------------------------------------------
Public Sub UpdateDataSet()
'Create a new dataset to hold the changes that have been made to the
main dataset.
Dim objDataSetChanges As trial2.trial2ds = New trial2.trial2ds
'Stop any current edits.
Me.BindingContext(objtrial2ds, "Table1").EndCurrentEdit()
'Get the changes that have been made to the main dataset.
objDataSetChanges = CType(objtrial2ds.GetChanges, trial2.trial2ds)
'Check to see if any changes have been made.
If (Not (objDataSetChanges) Is Nothing) Then
Try
'There are changes that need to be made, so attempt to update the
datasource by
'calling the update method and passing the dataset and any
parameters.
Me.UpdateDataSource(objDataSetChanges)
objtrial2ds.Merge(objDataSetChanges)
objtrial2ds.AcceptChanges()
Catch eUpdate As System.Exception
'Add your error handling code here.
Throw eUpdate
End Try
'Add your code to check the returned dataset for any errors that may
have been
'pushed into the row object's error.
End If
End Sub
----------------------------------------------------------------------------------------
Public Sub UpdateDataSet()
'Create a new dataset to hold the changes that have been made to the main
dataset.
Dim objDataSetChanges As trial2.trial2ds = New trial2.trial2ds
'Stop any current edits.
Me.BindingContext(objtrial2ds, "Table1").EndCurrentEdit()
'Get the changes that have been made to the main dataset.
objDataSetChanges = CType(objtrial2ds.GetChanges, trial2.trial2ds)
'Check to see if any changes have been made.
If (Not (objDataSetChanges) Is Nothing) Then
Try
'There are changes that need to be made, so attempt to update the
datasource by
'calling the update method and passing the dataset and any
parameters.
Me.UpdateDataSource(objDataSetChanges)
objtrial2ds.Merge(objDataSetChanges)
objtrial2ds.AcceptChanges()
Catch eUpdate As System.Exception
'Add your error handling code here.
Throw eUpdate
End Try
'Add your code to check the returned dataset for any errors that may
have been
'pushed into the row object's error.
End If
End Sub
---------------------------------------------------------------------------------------
Public Sub UpdateDataSource(ByVal ChangedRows As trial2.trial2ds)
Try
'The data source only needs to be updated if there are changes pending.
If (Not (ChangedRows) Is Nothing) Then
'Open the connection.
Me.OleDbConnection1.Open()
'Attempt to update the data source.
OleDbDataAdapter1.Update(ChangedRows)
End If
Catch updateException As System.Exception
'Add your error handling code here.
Throw updateException
Finally
'Close the connection whether or not the exception was thrown.
Me.OleDbConnection1.Close()
End Try
End Sub
Thanks in advance for any help you can give......
tattoo
One of my tables has, amongst others, 2 fields that are defined as
Date/Time fields. with a format of Medium Date.
In the VB Solution explorer I added a new form using the Data Form Wizard
over this table. This creates the appropriate Bound fields on the form
linked to the fields in the database.
The problem I've run into is, when I have put dates into these fields and
then add the record to the database, I sometimes have a need to clear those
dates and update the record with no date . but When I do, After pressing
the Update button, the date re-appears in the field. It hasn't been removed
from the database record..
Here is the code thath is responsible for doing the update. This code is all
generated by the form wizard.
I have also tried creating a simple test application in a completely
seperate directory with its own Db, that has one field in the table defined
as a date/time field.
In the Db the properties of the date field are: Format - Medium Date,
Required = No, and Indexed = No. Those are the only propertiies set.
When I say I'm blanking out the field on the VB Form I have tried multiple
things. Setting it to Zero, Setting it to Nothing, I'm not sure how to set
it to Null, maybe that's my problem ?
--------------------------------------------------------------------------
' Update Button
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Try
'Attempt to update the datasource.
Me.UpdateDataSet()
Catch eUpdate As System.Exception
'Add your error handling code here.
'Display error message, if any.
System.Windows.Forms.MessageBox.Show(eUpdate.Message)
End Try
Me.objtrial2ds_PositionChanged()
End Sub
----------------------------------------------------------------------------------------------
Public Sub UpdateDataSet()
'Create a new dataset to hold the changes that have been made to the
main dataset.
Dim objDataSetChanges As trial2.trial2ds = New trial2.trial2ds
'Stop any current edits.
Me.BindingContext(objtrial2ds, "Table1").EndCurrentEdit()
'Get the changes that have been made to the main dataset.
objDataSetChanges = CType(objtrial2ds.GetChanges, trial2.trial2ds)
'Check to see if any changes have been made.
If (Not (objDataSetChanges) Is Nothing) Then
Try
'There are changes that need to be made, so attempt to update the
datasource by
'calling the update method and passing the dataset and any
parameters.
Me.UpdateDataSource(objDataSetChanges)
objtrial2ds.Merge(objDataSetChanges)
objtrial2ds.AcceptChanges()
Catch eUpdate As System.Exception
'Add your error handling code here.
Throw eUpdate
End Try
'Add your code to check the returned dataset for any errors that may
have been
'pushed into the row object's error.
End If
End Sub
----------------------------------------------------------------------------------------
Public Sub UpdateDataSet()
'Create a new dataset to hold the changes that have been made to the main
dataset.
Dim objDataSetChanges As trial2.trial2ds = New trial2.trial2ds
'Stop any current edits.
Me.BindingContext(objtrial2ds, "Table1").EndCurrentEdit()
'Get the changes that have been made to the main dataset.
objDataSetChanges = CType(objtrial2ds.GetChanges, trial2.trial2ds)
'Check to see if any changes have been made.
If (Not (objDataSetChanges) Is Nothing) Then
Try
'There are changes that need to be made, so attempt to update the
datasource by
'calling the update method and passing the dataset and any
parameters.
Me.UpdateDataSource(objDataSetChanges)
objtrial2ds.Merge(objDataSetChanges)
objtrial2ds.AcceptChanges()
Catch eUpdate As System.Exception
'Add your error handling code here.
Throw eUpdate
End Try
'Add your code to check the returned dataset for any errors that may
have been
'pushed into the row object's error.
End If
End Sub
---------------------------------------------------------------------------------------
Public Sub UpdateDataSource(ByVal ChangedRows As trial2.trial2ds)
Try
'The data source only needs to be updated if there are changes pending.
If (Not (ChangedRows) Is Nothing) Then
'Open the connection.
Me.OleDbConnection1.Open()
'Attempt to update the data source.
OleDbDataAdapter1.Update(ChangedRows)
End If
Catch updateException As System.Exception
'Add your error handling code here.
Throw updateException
Finally
'Close the connection whether or not the exception was thrown.
Me.OleDbConnection1.Close()
End Try
End Sub
Thanks in advance for any help you can give......
tattoo