 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 15th, 2004, 01:24 PM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Updating DB
Of course the following code does not work but you can see where I'm going with it. My question is how do you deal with spaces or blank fields with updates?
sSQL = "UPDATE vendor Set " & _
" uiid = '" & CStr(Request.Form("uiid")) & "'" & _
" company = '" & CStr(Request.Form("company")) & "'" & _
If Len(Trim(Reques.Form("attn"))) <> 0 Then
" attn = '" & CStr(Request.Form("attn")) & "'" & _
End If
" WHERE key = " & Request("server_index") & ""
Set rs = Connect.Execute(sSQL)
How do I really update something without spaces and remove data in a field if the user has removed it from the form field?
|
|

March 15th, 2004, 01:32 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I must admit that I can't see where you're going....
What are you trying to accomplish? What do you mean with: How do I really update something without spaces and remove data in a field if the user has removed it from the form field?
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

March 15th, 2004, 02:03 PM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Sorry...
The first two fields are mandatory...because I know it's not empty I just update the fields.
The third field, I check to see if there is something in the form text box...if it's not blank I update the DB.
But what if the field in the database has "Joe" in it and the form text box has ""?
I guess I just don't know the best way to do an update...other than doing the following for each field:
If Len(Trim(Reques.Form("uiid"))) <> 0 Then
" UIIDfield = ' " & CStr(Request.Form("uiid")) & " ' "
else
" UIIDfield = " "
End If
But then when I do the update:
sSQL = "UPDATE vendor Set " & _
" uiid = ' " & UIIDfield " ' " & _
I may have BLANKS in my Database
|
|

March 15th, 2004, 02:10 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Well, doesn't that depend on your business rules rather than on coding rules?
What do you want to happen when the form field is empty? Should it overwrite the text in the database or not?
I think the easiest thing to overcome this (depending on your business logic), is to display the initial data in the update form. So, if the field initially contained Joe, and on postback it still contains Joe, updating the field doesn't really matter because the data stays the same. However, it's usually easier to update it anyway.
However, if the user changed Joe to John, an updated is definitely needed. If the user changed Joe to "", you'll have to assume their intentions are to leave the field blank, right?
If not, you may even need to elaborate a bit further about your requirements....
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

March 15th, 2004, 02:17 PM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Problem is you can't change "Joe" to "".
You get an error message
You have to change "Joe" to " ".
Now you have a field with a space in it.
|
|

March 15th, 2004, 02:39 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Right, but that sounds like the column in your database table doesn't support empty values. Make sure the column allows null values.
What database are you using?
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

March 15th, 2004, 03:10 PM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
|
|
I'm using Access.
|
|

March 15th, 2004, 03:23 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Well, in that case, go to the Access table designer, and make sure that the Required property for the field is set to No.
If that doesn't help, can you post the error you're getting?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

March 15th, 2004, 03:29 PM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Oh...my fields are all set to "No"...but the box under that says "Allow Zero Length"
thanks for the help.
|
|

March 15th, 2004, 03:37 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Take a look in the help for the Required and Allow Zero Length properties.
There are some subtle differences in how they behave.....
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
 |