Article View: be.comp.programming
Article #729Re: null waarden in datatable
From: John Bokma
Date: Sun, 14 May 2006 18:13
Date: Sun, 14 May 2006 18:13
36 lines
2042 bytes
2042 bytes
Peter <spetrelly@pandora.be> wrote:
> Als ik het goed begrijp, wil je bij een lege string ("") een
> null-waarde
> wegschrijven naar de database.
>
> Een check zou moeten volstaan?
>
> If txtDuur.text = "" then
> dr(0)(5) = dbnull.value
> else
> dr(0)(5) = CInt(TtxtDuur.Text)
> end if
>
> of misschien een try... catch?
>
> try
> dr(0)(5) = CInt(TtxtDuur.Text)
> catch
> dr(0)(5) = dbnull.value
> end try
Exceptions zijn voor uitzonderingsgevallen. Als "" een toegestane waarde
is zou ik zeker geen exception gebruiken om het af te vangen.
Daarnaast, het is altijd het beste om voor elke vorm van ingave een
correcte afhandeling te maken. Dus de 1e oplossing is IMO alleen juist als
de text slechts of een Int of leeg kan zijn. Wat je niet wilt is dat de
gebruiker "Hallo" in kan tikken, en dat dat op het scherm staat, terwijl
in de database NULL opgeslagen werd.
--
John Bokma
Voorbeeldscripts in Perl: http://johnbokma.com/perl/
Ervaren Perl / Java programmeur beschikbaar: http://castleamber.com/
Tevreden opdrachtgevers: http://castleamber.com/testimonials.html
Technical Details
Message-ID:
<Xns97C38671DB2DBcastleamber@130.133.1.4>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mailReferences:
<mn.70ea7d65b632223d.48459@internetfreakz.be.invalid> <ypD9g.424252$GM2.11651173@phobos.telenet-ops.be>Show Full Headers
Complete Article Headers
X-Google-Thread: fcea4,1065910732a62429
X-Google-Attributes: gidfcea4,public
X-Google-Language: DUTCH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: John Bokma <john@castleamber.com>
Newsgroups: be.comp.programming
Subject: Re: null waarden in datatable
Date: 14 May 2006 18:13:01 GMT
Organization: Castle Amber - software development
Lines: 36
Message-ID: <Xns97C38671DB2DBcastleamber@130.133.1.4>
References: <mn.70ea7d65b632223d.48459@internetfreakz.be.invalid> <ypD9g.424252$GM2.11651173@phobos.telenet-ops.be>
X-Trace: individual.net pqsfIYRhBPK8YX3QzX/JBgC8CFB3I9m7NC5oZGK8ozSp9OaGNO
User-Agent: Xnews/2005.10.18
X-Face: $7h&5K*ZL9*ZQ\6Hco2"V?1dD*C<ab^>zlws[S%i0b,@gKk|[,)Y-<hk143{.Ov"x{({zo( l,N\m`-_^nJfVQdEyt+-uAP^7WG]5mHj9&::7X-qK;Yv;xmRvNWQR"_igw+cr5WMj;6:zlj<R80Ei@ $gGWq&*{FL*kC*a