PC Review


Reply
Thread Tools Rate Thread

Is this behaviour normal?

 
 
Özden Irmak
Guest
Posts: n/a
 
      12th Jan 2005
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


 
Reply With Quote
 
 
 
 
Diego Deberdt
Guest
Posts: n/a
 
      12th Jan 2005
Whether the column allows DBNull or not is not determined by whether it is
an identity column, but by whether the property "AllowDBNull" of the column
is True or False. You need to take a look at the schema for the DataTable
object that you are working with.

The reason that you don't get an exception when you leave the TextBoxes
empty is that an empty TextBox does not get translated to DBNull, but is
inserted into the DataRow field as a zero-length string!

The solution to your problem is very simple: respect the constraints that
exist on your table and you'll be fine!

"Ö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
>
>



 
Reply With Quote
 
Özden Irmak
Guest
Posts: n/a
 
      12th Jan 2005
Hello Diego,

Thank you for your answer but I think you got me wrong.

It would be true if I update that new row into the database table without
filling CustomerId field, but this error occurs when I call "AddNew()"
Method of BindingContext object.

I made a simple screen in VB6 uses that table (An Adodc control and some
textboxes bound to the fields in that table) and it successfully works
(trying to call addnew method of ADODB.Recordset), what do you say about
this?

Regards,

Özden

"Diego Deberdt" <(E-Mail Removed)> wrote in message
news:kSfFd.29027$(E-Mail Removed)...
> Whether the column allows DBNull or not is not determined by whether it is
> an identity column, but by whether the property "AllowDBNull" of the
> column
> is True or False. You need to take a look at the schema for the DataTable
> object that you are working with.
>
> The reason that you don't get an exception when you leave the TextBoxes
> empty is that an empty TextBox does not get translated to DBNull, but is
> inserted into the DataRow field as a zero-length string!
>
> The solution to your problem is very simple: respect the constraints that
> exist on your table and you'll be fine!
>
> "Ö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
>>
>>

>
>



 
Reply With Quote
 
Marina
Guest
Posts: n/a
 
      12th Jan 2005
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
>
>



 
Reply With Quote
 
Özden Irmak
Guest
Posts: n/a
 
      12th Jan 2005
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
>>
>>

>
>



 
Reply With Quote
 
Diego Deberdt
Guest
Posts: n/a
 
      12th Jan 2005
I think you need to read up on DataSets and DataTables. What you don't seem
to understand is that your DataSet contains a database schema similar to
that which exists on the database, with similar constraints, like Unique and
FK. At the same time, there is no connection from the DataSet to your
database, but this does not matter. AddNew() fails because of the
constraints that are defined on you DataTable object.

"Özden Irmak" <ozdenirmak(at)isnet(dot)net(dot)tr> wrote in message
news:ezcxthO%(E-Mail Removed)...
> Hello Diego,
>
> Thank you for your answer but I think you got me wrong.
>
> It would be true if I update that new row into the database table without
> filling CustomerId field, but this error occurs when I call "AddNew()"
> Method of BindingContext object.
>
> I made a simple screen in VB6 uses that table (An Adodc control and some
> textboxes bound to the fields in that table) and it successfully works
> (trying to call addnew method of ADODB.Recordset), what do you say about
> this?
>
> Regards,
>
> Özden
>
> "Diego Deberdt" <(E-Mail Removed)> wrote in message
> news:kSfFd.29027$(E-Mail Removed)...
> > Whether the column allows DBNull or not is not determined by whether it

is
> > an identity column, but by whether the property "AllowDBNull" of the
> > column
> > is True or False. You need to take a look at the schema for the

DataTable
> > object that you are working with.
> >
> > The reason that you don't get an exception when you leave the TextBoxes
> > empty is that an empty TextBox does not get translated to DBNull, but is
> > inserted into the DataRow field as a zero-length string!
> >
> > The solution to your problem is very simple: respect the constraints

that
> > exist on your table and you'll be fine!
> >
> > "Ö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
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
Marina
Guest
Posts: n/a
 
      13th Jan 2005
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
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
animated gif - behaviour like a normal movie - is this possible? Hermann Maier Microsoft Powerpoint 0 18th May 2009 08:46 AM
Is this an Outlook normal behaviour and Why? message recall failure delay? Microsoft Outlook Calendar 0 12th Sep 2008 02:11 AM
Drop Down List - is this normal behaviour? G Microsoft ASP .NET 1 2nd Mar 2007 02:22 PM
normal drag and drop behaviour assaf Microsoft Dot NET Framework Forms 1 25th Sep 2004 03:51 PM
Normal behaviour (Perfection 4870)? Cerridwen Scanners 3 2nd May 2004 09:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:41 AM.