By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,682 Members | 1,980 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,682 IT Pros & Developers. It's quick & easy.

Setting the data base value to Null via a bound Textbox

P: n/a

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?
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"WhiskyRomeo" wrote:

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?

Jul 21 '05 #2

P: n/a
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
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.