I am writing a front end for an existing Access database (which i dont
really want to change if i can help it) in VB.NET.
For simplicity, i am databinding all controls on the screen using an
untyped dataset.
I have a phoneno column in the database which is setup as follows:
Required: No
Allow zero length: No
Data Type: Text
When i bind this column to a textbox, it correctly shows the value
recorded on the database in the box, including when the database
column is set to Null (when it shows nothing in the textbox)
When i put some text in the box, the table is updated correctly,
however, if i delete the contents of the textbox, i get the following
error when the adapter.update call is made:
Field 'tblAddress.ContactPhoneNo' cannot be a zero-length string
What i actually want it to do is write Null to the database column
rather than a 0 length string.
I am using a command builder, so that handles the update of the
column, and sure enough, checking the parameter for the update of the
phone no col, it shows "" {String}.
Is there a way to write Null to this field without having to write the
update statements myself?
Any help much appreciated
Thanks
Malcolm
Sijin Joseph - 12 Oct 2004 04:54 GMT
Yes, you will have to use the Parse event of the Binding to change empty
strings to DBNull
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fSystemWindowsFormsBindingClassParseTopic.asp
Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
> I am writing a front end for an existing Access database (which i dont
> really want to change if i can help it) in VB.NET.
[quoted text clipped - 31 lines]
>
> Malcolm
Malcolm - 12 Oct 2004 12:09 GMT
Thanks, i found an article yesterday which contained an example of the
Parse event, it was just what i needed
Malcolm
> Yes, you will have to use the Parse event of the Binding to change empty
> strings to DBNull
[quoted text clipped - 3 lines]
> http://www.indiangeek.net
> http://weblogs.asp.net/sjoseph