Best practice for inserting new DataRows with lots of 'not null'-columns

L

Lorenz Kahl

Hi again,

I'm pretty new to Winforms & DataBinding and I'm currently running into
a lot of issues. Sorry if this has been explained before.

I have a DataSet containing a table 'Member' that holds a lot of columns
with info about members. Most of these columns are declared to be 'not
null' in the DB.

My WinForm for displaying members consists of a Listbox showing basic
info (full name) of a member, and a Textbox for each column showing the
details of the currently selected member. Ok, pretty much standard.

I'd like to have a button 'insert new member'. When it is pressed I'd
like to have a new (empty) entry in my Listbox and the detail-Textboxes
blanked out.

I tried it the way as it's propagated in many tutorials and books I found:
* use the NewRow()-method of the Member-table
* add it to the Member-table

But when I try to add it all the 'NoNullAllowedException's are fired -
ok that's what they are there for ;-)

I'm looking for a best practice for this one - since it is so standard
there must be someone with a good solution.

I'd like to avoid creating a seperate 'create new member dialog' that
duplicates all the fields on the other form, so i cann collect data
before adding the new row...

Any suggestions greatly appreciated,
Lorenz
 
T

Thomas

If I'm not mistaken, can't you set a default value on a DataColumn? I
believe that would solve your problem.


Thomas
 
L

Lorenz Kahl

Hi,

thank you both for your answers. I still don't think they'll solve my
problem.

I think it makes no sense filling in a default value in not nullable
fields. The not null-constraint enforces a user input. What would be a
good default value for an email address or a telephone number anyway?

Chris said:
Don't add the row to the member table until the user hits the save button.

Well that's what I would like to do. But how do I let the user fill in
the values if the columns of the row cannot be bound to the controls?
In order to 'display the empty row' for the user to be able to make the
proper input, it must be added to the table beforehand, because all the
textboxes (used for display and editing) are bound to that DataTable.
And that's where the clash is.

One way I thought of would be to disable the EnforceConstraints property
temporarily - but that might lead to a bunch of other problems. Maybe
it's really the best way to have a seperate modal form for creating and
filling a new MemberRow...

But I think there are other ways that are more elegant...
 
G

Guest

Use '' as default value

Lorenz Kahl said:
Hi,

thank you both for your answers. I still don't think they'll solve my
problem.


I think it makes no sense filling in a default value in not nullable
fields. The not null-constraint enforces a user input. What would be a
good default value for an email address or a telephone number anyway?



Well that's what I would like to do. But how do I let the user fill in
the values if the columns of the row cannot be bound to the controls?
In order to 'display the empty row' for the user to be able to make the
proper input, it must be added to the table beforehand, because all the
textboxes (used for display and editing) are bound to that DataTable.
And that's where the clash is.

One way I thought of would be to disable the EnforceConstraints property
temporarily - but that might lead to a bunch of other problems. Maybe
it's really the best way to have a seperate modal form for creating and
filling a new MemberRow...

But I think there are other ways that are more elegant...
 

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