Author |
Topic  |
|
TerryG
Junior Member
 
United Kingdom
179 Posts |
Posted - 29 May 2001 : 11:29:32
|
Hi, I am starting to design & develop a little app in ASP & ADO for my Intranet, so I can see I am going to be posting alot here over the next few weeks.
To start with, I set up my Access DB so it would not accept zero length strings, and wrote some ASP to check for zero length strings before trying to insert a field, something like: If Len(Request.Form("myField")) > 0 Then strInsert = strInsert & ",myField" strValues = strValues & ",'" & Cstr(Request.Form("myFieldinDB")) & "'" Now I am beginning to wonder if this was a sensible thing to do as if a user wants to delete an existing field (say he's saved a 20 char string) the database will not show his new zero length string as its not allowed, worse still the old 20 char string will still be in the DB! Now I am thinking I will have to put a little function on the client-side which fires when a field changes to a zero length string and changes it to " ", ie an empty 1 char string.
Should I have allowed zero length strings in the DB in the first place? the reason I did not was that there are about 100 fields which the user does not need to complete initially.
|
|
camusflage
Starting Member
USA
26 Posts |
Posted - 29 May 2001 : 11:32:25
|
Understand that there is a difference between null and empty. If you set a default to "" for a field, and not allow nulls, when the row is inserted, it is inserted with empty strings, rather than null fields, if data is not supplied for the particular field. This is assuming of course that you don't want to allow nulls, for whatever reason.
Mike
|
 |
|
TerryG
Junior Member
 
United Kingdom
179 Posts |
Posted - 29 May 2001 : 11:50:09
|
I had not made that distinction between the two, thanks.
I have not set any default for the fields if the user inputs no data, however I thought the form was returning the zero length string for these 'untouched by the user' fields, and that it would be 'bad' to insert that into the DB (presumably overwrighting a Null if its a new record?). Am I wrong? whats 'in' an empty textarea or text box when the forms being submitted.
|
 |
|
camusflage
Starting Member
USA
26 Posts |
Posted - 29 May 2001 : 12:59:53
|
If you do not allow nulls, and set a default as "", then if a row is inserted, it will insert "" wherever another value isn't set. If your code does not like nulls, sending a "" is preferable to sending nulls. From vbscript, the isempty() and isnull() functions will return different values for "" vs <null>. Generally speaking, I'll set to non-null, and use "" for the default of strings where input is optional, simply because <null> and "" represent different concepts.
Mike
|
 |
|
Dan Martin
Average Member
  
USA
528 Posts |
Posted - 29 May 2001 : 18:17:22
|
From my experience, setting "Allow 0 length fields" in Access to "No", when that database is the back end for a ASP front end, is a BAD IDEA. Sooner or later, a user will find a way to submit a 0 length field into your form, and they will hit an error. Then you get an email saying "Why doesn't it work?"
On your add/update you can always do:
If myField = "" Then myField = " "
However, why do this? Is there any reason "" isn't going to work?
I broke down a long time ago, and now I ALWAYS allow 0 length. If I want a field to be REQUIRED, then I program that into the ASP, and not the database.
But, that's really a matter of opinion, and I know there are probable others who would adamately argue the other side.
-Dan
|
 |
|
camusflage
Starting Member
USA
26 Posts |
Posted - 29 May 2001 : 18:26:46
|
quote:
But, that's really a matter of opinion, and I know there are probable others who would adamately argue the other side.
I'm not one of them. I use DB constraint enforcement if and only if it's either a generated field (inside the db), if it's a key, or if there's a reason for it to never be bigger (state is 2 characters). It's not the DB's job to make sure the data is what I want it to be, puking if it's not. Front-end processing does the data massaging.
Mike
|
 |
|
Doug G
Support Moderator
    
USA
6493 Posts |
Posted - 29 May 2001 : 20:03:30
|
Does anyone know how to make the default for Access 2000 'allow zero length string' to be true?
I almost always allow "", it gets tiresome to change the field definition.
====== Doug G ====== |
 |
|
TerryG
Junior Member
 
United Kingdom
179 Posts |
Posted - 30 May 2001 : 08:18:29
|
OK Guys, you have convinced me, the DB is set to accept zero length strings now, and all validation will be on the client side. Many thanks for everyones help on this.
|
 |
|
|
Topic  |
|