I am guessing that calling AddNew on the bindingcontext is the equivalent of
adding a new datarow to the datatable. That's what it does for you behind
the scenes. The row automatically becomes part of the datatable, and then
you get the problem since it checks the constraint right away. The way
binding works, is that the row is always part of the datasource - otherwise
how would it know when it is OK to actually add it.
From then on, any values filled in are placed in the datarow. But the
error already occurred.
"Özden Irmak" <ozdenirmak(at)isnet(dot)net(dot)tr> wrote in message
news:eW59QLP%(E-Mail Removed)...
> Hello Marina,
>
> Thank you for your answer...
>
> I can understand to get an exception if I try to update a datarow but this
> is not the case.
>
> I'm not adding any empty datarow to datatable's collection, nor calling
any
> update methods of both the dataset or dataadapter. All I'm doing is to
call
> the "AddNew" method of BindingContext. This should cause all the bound
> controls on a form to clear their texts/values and wait for input for the
> new record. Having a "not allow null" field shoudln't cause this and this
> case is not reproduced in any other platfom (Neither in VB6 nor on Delphi)
>
> Regards,
>
> Özden
>
> "Marina" <(E-Mail Removed)> wrote in message
> news:uh8BZlO%(E-Mail Removed)...
> > The field does not allow nulls. So when you add a new row to the table,
> > guess what the value of that field is? It is null. But the table does
not
> > allow nulls for that column so you get the error. The table checks the
> > constraints.
> >
> > What you need to do is create the row, let the user fill in an id for
it,
> > set that column in the row and only then, can you add it to the
datatable.
> >
> > Now, this really defeats the whole purpose of databinding, since one
would
> > naturally want to add a blank row to the table and let the user fill in
> > the
> > values. But there doesn't seem to be good support for this.
> >
> > "Özden Irmak" <ozdenirmak(at)isnet(dot)net(dot)tr> wrote in message
> > news:O7MSAJO%(E-Mail Removed)...
> >> Hi,
> >>
> >> I have some simple dataentry screens, textboxes are bound into a
> > datasource.
> >>
> >> I connect to Sql Server 2000. When the user wants to add a new record,
I
> >> call "AddNew()" method of bindingcontext but it gives me an error
saying
> >> "CustomerId cannot be null value". This field is int and does not allow
> >> nulls. But I don't do any posting of the data, just adding a new onw?
The
> >> field is not marked as an identity.
> >>
> >> In another screen there are varchar fields and they also don't allow
> >> nulls
> >> but I don't get this error?
> >>
> >> Isn't this weird?
> >>
> >> I'm using VS.Net 2003 and C#.
> >>
> >> Any help?
> >>
> >> Regards,
> >>
> >> Özden
> >>
> >>
> >
> >
>
>
|