.NETGURU
Best practice for inserting new DataRows with lots of 'not null'-columns
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

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
Reply to this message...
 
    
Thomas
If I'm not mistaken, can't you set a default value on a DataColumn? I
believe that would solve your problem.

Thomas

"Lorenz Kahl" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Chris Spahn (VIP)
Don't add the row to the member table until the user hits the save button.

Chris

"Thomas" wrote:

[Original message clipped]

Reply to this message...
 
    
Lorenz Kahl
Hi,

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

[Original message clipped]

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 Spahn wrote:
> 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...

Reply to this message...
 
    
KC (VIP)
Use '' as default value

"Lorenz Kahl" wrote:

[Original message clipped]

Reply to this message...
 
 
System.Data.DataColumn
System.Data.DataSet
System.Data.DataTable
System.Data.NoNullAllowedException
System.Web.UI.DataBinding




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification