Groups | Blog | Home
all groups > dotnet windows forms databinding > october 2004 >

dotnet windows forms databinding : Problem binding TextBox to array of DataRows


Steve Amey
10/28/2004 3:31:07 PM
Hi all

I am getting the following error when binding some TextBoxes to an array of
DataRows:

Property accessor 'AddressLine3' on object 'dsMyDataSet+AddressRow' threw
the following exception:'Cannot get value because it is DBNull.'

I have been binding to DataTables until now, but I do need the ability to
bind to arrays of DataRows. Does anyone know how to get around this problem
and still be able to bind to DataRows?

Here is the code:
------------------------
Public Sub SetDataBinding(ByVal rows() As dsCABS.AddressRow)
' The Properties of the control adsAddress are just references to the
TextBoxes
Me.grdList.SetDataBinding(rows, "")
Me.adsAddress.AddressLine1.DataBindings.Add("Text", rows,
"AddressLine1")
Me.adsAddress.AddressLine2.DataBindings.Add("Text", rows,
"AddressLine2")
Me.adsAddress.AddressLine3.DataBindings.Add("Text", rows,
"AddressLine3")
Me.adsAddress.Locality.DataBindings.Add("Text", rows, "Locality")
Me.adsAddress.Town.DataBindings.Add("Text", rows, "Town")
Me.adsAddress.County.DataBindings.Add("Text", rows, "County")
Me.adsAddress.Country.DataBindings.Add("Text", rows, "Country")
Me.adsAddress.PostCode.DataBindings.Add("Text", rows, "PostCode")
End Sub
------------------------
Kind Regards,
Steve.

Steve Amey
10/28/2004 3:51:34 PM
Hi all

No worries, have found the answer.

HOW TO: Make a Typed DataSet Return a Default Value Instead of DBNull by
Using Visual Basic .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;318039

Regards,
Steve.

[quoted text, click to view]

AddThis Social Bookmark Button