none
BindingSource.AddNew with AllowDBNull false

    Question

  • Hi,

     

    I'm using bindingsource in VB.Net (2.0).  I have an editform with a bindingsource connected to a typed datatable.  My datatable has some datacolumns (like Name) with AllowDBNull set to false.  When I load this form in add mode, I need to move the bindingsource to a new record.  I tried BindingSource.AddNew, but it launch an exception (Column Name does not allow null).  I don't use bindingnavigator for my editform because this control has too many restrictions to be usable in a business environment.  It is not possible to catch event and I needed to forget this idea after many days to try to make it work.  However, I use it for my search form (to list all the record in some cases) and it works fine.   I tried to catch AddNew event without success.  I tried to create a 3-tier application and I think it is the right way to achieve this, is it?

     

    Any idea would be appreciate

    Thank you

    Wednesday, May 07, 2008 1:34 PM

Answers

  • When you call the bindingsource's addnew method a new row is created for you to add values to.  Once you move to another record (or add another row) the row is added to the datatable.  The row is not added right away to prevent errors like you are talking about.  Is it possible the AddNew method is getting called twice?
    Wednesday, May 07, 2008 5:23 PM

All replies

  • The datatable has a TableNewRow event which fires when you add a new row to the datatable.  I would use that event.

    http://msdn.microsoft.com/en-us/library/system.data.datatable.tablenewrow.aspx
    Wednesday, May 07, 2008 3:43 PM
  • Hi,

     

    Thank you for your help.  I already use TableNewRow to push some default values like active = true, etc.  However, for that problem, I cannot push Default value because it is the name, so It is not very interesting for the user to view a dummy name in the textbox when he add a new entry.,..

     

    Thank you

    Wednesday, May 07, 2008 4:39 PM
  • When you call the bindingsource's addnew method a new row is created for you to add values to.  Once you move to another record (or add another row) the row is added to the datatable.  The row is not added right away to prevent errors like you are talking about.  Is it possible the AddNew method is getting called twice?
    Wednesday, May 07, 2008 5:23 PM
  • Thank you very much.  it is exactly the problem I had.  My search form had an Add button (bindingnavigator) and this button call an Addnew without code, so when I called AddNew in my editform, I got this problem because I tried to add a second row.

     

    Thank you for your help

    Wednesday, May 07, 2008 5:37 PM