set DataColumn.DefaultValue to false

A

Aamir Ghanchi

How can I set the DefaultValue property of DataColumn to false in C#

this.objdsMyDataSet.tblMyTable.MyBooleanColumn.DefaultValue = false;

I have also tried setting it to System.Data.SqlTypes.SqlBoolean.False;

but in either case I get ArgumentException.

What is wrong, it looks straightforward to me.

thanks

Aamir
 
A

Aamir Ghanchi

It is a Bit Column (0/1)
I am doing this because the binded CheckBoxes on my form
cause problem when AddNew method of BindingManagerBase is
used and the Position property does not get updated.



see this bug:
http://support.microsoft.com/default.aspx?scid=kb;en-
us;326440

I have also tried setting it to 0 (zero) besides false,
but get InvalidCastException instead
 
A

Aamir Ghanchi

Problem is Solved.

setting it to 0 (zero) did the work.
I was confusing this error with the similar error I was
getting for the DateTimePicker control which was being
bind to a smalldatetime column having <NULL> value for
that row.
I had to unbind the Value property of DateTimePicker
control from the smalldatetime column of the table and
that fixed it.

It would be nice in VS.Net if we get the exceptions that
point to the exact control causing the problem, but that
is not the case unfortunately. This exception was being
caused in some mscorlib.dll how would I know what to look
for. There are some still loose ends that Microsoft needs
to fix.

follwing is the exception I got in the MDIParent form, not
related to the actual ChilForm that had the problem
control on it:

An unhandled exception of
type 'System.InvalidCastException' occurred in mscorlib.dll

Additional information: Object cannot be cast from DBNull
to other types.
 

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