TextBox.DataBindings DBNull x Empty value

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

Guest

Hi guys!

I've bound some TextBoxes with a DataSet in my code. Now I'm in doubt about
how to handle empty values as DBNull.Value.
If I erase all textbox's content and call DataAdpater.Update, the system
commit in my SQL Server an empty value.

Could you give some tips to commit those values as DBNull.Value?

Thanks
 
I would recommend trying something like the following. I would think that
you could Format it coming out of the database to an empty string and then
have the Parse routine put it back to DBNull.Value.

Setup your databinding and formatting:
Dim dbnTelephone As New Binding("Text", ds.Patients, "Telephone")
AddHandler dbnTelephone.Format, AddressOf
AppRoutines.StringToTelephone
AddHandler dbnTelephone.Parse, AddressOf AppRoutines.TelephoneToString
txtTelephone.DataBindings.Add(dbnTelephone)

The Handlers for these events:

Shared Sub StringToTelephone(ByVal sender As Object, ByVal e As
ConvertEventArgs)
If Not e.Value Is DBNull.Value Then
e.Value = FormatTelephone(e.Value)
End If
End Sub

Shared Sub TelephoneToString(ByVal sender As Object, ByVal e As
ConvertEventArgs)
If Not e.Value Is DBNull.Value Then
e.Value = ParseTelephone(e.Value)
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top