Setting the data base value to Null via a bound Textbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a bound textbox (bindings are set at design time) to a dataset
column. Sometimes the value of this textbox must be set so that the
underlying database field gets updated to null when using the update method
of the dataadapter.

Since the dataset field datatype is INT32 it gets set to the empty string
equivalent which is 0. Zero is not a valid value so the update fails.

Can this be done without changing the SQL of the udpdate mathed?
 
I need to add, setting the textbox value to "" or nothing in code does not
affect the
HasChanges property of the underlying dataset. So, for example,
dsOrg1.HasChanges is false.

Setting the value directly in the dataset does not work since an interger
can't accept DBNull.Value as a value.

Yet, when you initially load the dataset, that column can be null if the
underlying database field is Null.

wr
 
Whiskey,

Have a look at this sample I once made, maybe it can help you.

\\\
Private Sub myroutine()
Mybinding = New Binding("Text", ds.Tables(0), "mydatfield")
textdatfield.DataBindings.Add(Mybinding)
AddHandler mybinding.Format, AddressOf DBdateTextbox
AddHandler mybinding.Parse, AddressOf TextBoxDBdate
End sub
Private Sub DBdateTextbox(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
Dim datum As Date
datum = CDate(cevent.Value)
cevent.Value = datum.ToString("d")
End If
End Sub
Private Sub TextBoxDBdate(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value.ToString = "" Then
cevent.Value = DBNull.Value
End If
End Sub
///

I hope this helps?

Cor
 
Back
Top