A simple binding question

D

Doug Lowe

Hi all, this might be a simple question, but then again maybe not. I'm
binding a text box in a Windows form to a column that does not allow nulls.
The problem is, if I do AddNew, the user leaves the field blank, and I call
EndCurrentEdit, I get a "null not allowed" exception. What I want is to put
an empty string in the column. Is there something I'm overlooking?

--Doug
 
S

Shane Brodie

Try setting the content of your text field to "" after invoking your AddNew
call

AddNew()
txtMyField.Text = ""

Regards

Shane
 
D

Doug Lowe

Thanks, Shane. That doesn't help though. I still get the exception. It does
work if I set the text box to " " (one space) but that's not at all what I
want.

The exception is happening before I get to the EndCurrentEdit method
call...before the click event handler is called, in fact. It must be burried
somewhere in the binding manager. Its as if the binding manager is looking
at my text box, seeing that I didn't enter anything, and trying to set the
bound column to null even though the column doesn't allow nulls.

I hope I'm missing something real obvious :)

--Doug
 
A

Abul Hasan

Hey,

Try to create a default constraint on the column. for instance 'N/A' or
'UNKNOWN'
 

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

Top