Wrox Programmer Forums
|
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
 
Old March 15th, 2004, 01:24 PM
Authorized User
 
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default 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?

 
Old March 15th, 2004, 01:32 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old March 15th, 2004, 02:03 PM
Authorized User
 
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default

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

 
Old March 15th, 2004, 02:10 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old March 15th, 2004, 02:17 PM
Authorized User
 
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default

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.

 
Old March 15th, 2004, 02:39 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old March 15th, 2004, 03:10 PM
Authorized User
 
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default

I'm using Access.

 
Old March 15th, 2004, 03:23 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old March 15th, 2004, 03:29 PM
Authorized User
 
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default

Oh...my fields are all set to "No"...but the box under that says "Allow Zero Length"

thanks for the help.

 
Old March 15th, 2004, 03:37 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with updating the db using servlet Behl_Neha Java Databases 1 December 24th, 2007 06:08 AM
I am an idiot....DB not updating w/o Agent? Raconteur SQL Server 2000 4 April 24th, 2007 11:30 AM
Updating an Access 200 db Gandalf_the_Grey Classic ASP Basics 3 June 27th, 2006 07:09 AM
updating db with dataAdapter/dataTable problem mm1234 ADO.NET 0 November 19th, 2003 06:49 AM
Updating an Access DB stu9820 ASP.NET 1.0 and 1.1 Basics 1 September 30th, 2003 01:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.