473,566 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP Trim() Function Error

Here is the general problem:

Information is taken from a form (consisting of text boxes, drop down
lists et cetera) and submitted to an Access database. Before the data
is inserted into the database, trailing and leading spaces are removed
using a call to the Trim()function.

This works the first time data is inserted into the database. However,
if the data is modified (via web forms) and then resubmitted (after
calling the Trim() function) an extra leading space (occasionally two)
is randomly inserted.

For example,

I enter info for the following variables:

NAME: ' Bill'
AGE: ' 20 '

The Access database looks like this:

NAME: 'Bill'
AGE: '20'

I then edit the record in the database, changing the name to 'Peter'
and age to '30':

NAME: ' Peter '
AGE: ' 30 '

The Access database then looks like this:

NAME: ' Peter'
Age: ' 30'

OR

sometimes like this:

NAME: ' Peter'
AGE: '30'

It appears to be total random, anyone have any suggestions?
Jul 19 '05 #1
6 4091
Need to see code that handles the updating of your records.

Ray at work

"Dominic" <dj******@hotma il.com> wrote in message
news:e2******** *************** ***@posting.goo gle.com...
Here is the general problem:

Information is taken from a form (consisting of text boxes, drop down
lists et cetera) and submitted to an Access database. Before the data
is inserted into the database, trailing and leading spaces are removed
using a call to the Trim()function.

This works the first time data is inserted into the database. However,
if the data is modified (via web forms) and then resubmitted (after
calling the Trim() function) an extra leading space (occasionally two)
is randomly inserted.

For example,

I enter info for the following variables:

NAME: ' Bill'
AGE: ' 20 '

The Access database looks like this:

NAME: 'Bill'
AGE: '20'

I then edit the record in the database, changing the name to 'Peter'
and age to '30':

NAME: ' Peter '
AGE: ' 30 '

The Access database then looks like this:

NAME: ' Peter'
Age: ' 30'

OR

sometimes like this:

NAME: ' Peter'
AGE: '30'

It appears to be total random, anyone have any suggestions?

Jul 19 '05 #2

Thanks for the reply.

I'll provide code for, say, a text box to keep things simple (the
project I'm working on consists of hundreds of variables spread over
many pages).

Data is entered using a standard form and stored in session variables
(I'm not too pleased about having to use session variables but nothing
else will do the job), so...

on submission the text box variable is retrieved using:
Session("PA_str PostCode") = Request.Form("P A_txtPostCode")
spaces are then removed using the Trim() function:
Session("PA_str PostCode") = Trim(Session("P A_strPostCode") )
a connection to the database is opened using:
Set Connection = Server.CreateOb ject("ADODB.Con nection")
Connection.Open "PROVIDER=MICRO SOFT.JET.OLEDB. 4.0;DATA SOURCE=" & dbPath

where the variable dbPath contains the location of the database.

data is inserted into the database using:
strSQL= ""
strSQL = strSQL & "INSERT INTO ProjectAddress "
strSQL = strSQL & "(PA_strPostCod e) "
strSQL = strSQL & "VALUES ("
strSQL = strSQL & "'" & Session("PA_str PostCode") & "'"
strSQL = strSQL & ");"
Connection.Exec ute strSQL, lngRecsAffected , adCmdText Or >

adExecuteNoReco rds

The editing code is identical apart from the data is retrieved using a
recordset, modified via a web form and then inserted back into the
database using an identical expression to the INSERT statement except
with UPDATE.

Note that before data in reinserted back into the database calls to the
request.form and trim functions are made.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #3

"Dominic Marsat" <dj******@hotma il.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
The editing code is identical apart from the data is retrieved using a
recordset, modified via a web form and then inserted back into the
database using an identical expression to the INSERT statement except
with UPDATE.
You said that when the data is INSERTed, it is fine. And it's only not fine
when you UPDATE it. So, please post the UPDATE code, not the INSERT code!

Also, please see www.aspfaq.com/5007.

Ray at home

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #4
Here is the UPDATE code. I've sent the whole function instead of editing
bits out. I've noticed that I haven't set the strSQL string to " " as I have
done in the INSERT function, however this shouldn't matter because the first
line of the function effectively does this. Thanks, Dom

' Update the project address database records
Function UPDATE_PA()
strSQL= "UPDATE ProjectAddress SET PA_strOrderNumb er= ' " &
Session("PA_str OrderNumber") & " ', "
strSQL=strSQL & "PA_strQuotatio nRef= ' " & Session("PA_str QuotationRef") &
" ', "
strSQL=strSQL & "PA_strProjectS tatus= ' " &
Session("PA_str ProjectStatus") & " ', "
strSQL=strSQL & "PA_strAddress1 = '" & Session("PA_str Address1") & "', "
strSQL=strSQL & "PA_strAddress2 ='" & Session("PA_str Address2") & "', "
strSQL=strSQL & "PA_strAddress3 = '" & Session("PA_str Address3") & "', "
strSQL=strSQL & "PA_strAddress4 = '" & Session("PA_str Address4") & "', "
strSQL=strSQL & "PA_strCity = '" & Session("PA_str City") & "', "
strSQL=strSQL & "PA_strCoun ty= '" & Session("PA_str County") & "', "
strSQL=strSQL & "PA_strPostCode = '" & Session("PA_str PostCode") & "' "
strSQL=strSQL & "WHERE ID=" & Session("ID")
Connection.Exec ute strSQL, lngRecsAffected , adCmdText Or adExecuteNoReco rds
End Function
"Ray at <%=sLocation% > [MVP]" <myfirstname at lane34 dot com> wrote in
message news:eN******** *****@TK2MSFTNG P10.phx.gbl...

"Dominic Marsat" <dj******@hotma il.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
The editing code is identical apart from the data is retrieved using a
recordset, modified via a web form and then inserted back into the
database using an identical expression to the INSERT statement except
with UPDATE.
You said that when the data is INSERTed, it is fine. And it's only not

fine when you UPDATE it. So, please post the UPDATE code, not the INSERT code!

Also, please see www.aspfaq.com/5007.

Ray at home

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Jul 19 '05 #5
You have leading spaces.

strSQL= "UPDATE ProjectAddress SET PA_strOrderNumb er= ' " &
Session("PA_str OrderNumber") & " ', "
--------------------------------------------------------^

strSQL=strSQL & "PA_strQuotatio nRef= ' " & Session("PA_str QuotationRef") &
" ', "
---------------------------------------^

Ray at home

"Dominic Marsat" <djmarsatAThotm ail.com> wrote in message
news:um******** ******@TK2MSFTN GP11.phx.gbl...
Here is the UPDATE code. I've sent the whole function instead of editing
bits out. I've noticed that I haven't set the strSQL string to " " as I have done in the INSERT function, however this shouldn't matter because the first line of the function effectively does this. Thanks, Dom

' Update the project address database records
Function UPDATE_PA()
strSQL= "UPDATE ProjectAddress SET PA_strOrderNumb er= ' " &
Session("PA_str OrderNumber") & " ', "
strSQL=strSQL & "PA_strQuotatio nRef= ' " & Session("PA_str QuotationRef") & " ', "
strSQL=strSQL & "PA_strProjectS tatus= ' " &
Session("PA_str ProjectStatus") & " ', "
strSQL=strSQL & "PA_strAddress1 = '" & Session("PA_str Address1") & "', "
strSQL=strSQL & "PA_strAddress2 ='" & Session("PA_str Address2") & "', "
strSQL=strSQL & "PA_strAddress3 = '" & Session("PA_str Address3") & "', "
strSQL=strSQL & "PA_strAddress4 = '" & Session("PA_str Address4") & "', "
strSQL=strSQL & "PA_strCity = '" & Session("PA_str City") & "', "
strSQL=strSQL & "PA_strCoun ty= '" & Session("PA_str County") & "', "
strSQL=strSQL & "PA_strPostCode = '" & Session("PA_str PostCode") & "' "
strSQL=strSQL & "WHERE ID=" & Session("ID")
Connection.Exec ute strSQL, lngRecsAffected , adCmdText Or adExecuteNoReco rds End Function
"Ray at <%=sLocation% > [MVP]" <myfirstname at lane34 dot com> wrote in
message news:eN******** *****@TK2MSFTNG P10.phx.gbl...

"Dominic Marsat" <dj******@hotma il.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
The editing code is identical apart from the data is retrieved using a
recordset, modified via a web form and then inserted back into the
database using an identical expression to the INSERT statement except
with UPDATE.


You said that when the data is INSERTed, it is fine. And it's only not

fine
when you UPDATE it. So, please post the UPDATE code, not the INSERT code!
Also, please see www.aspfaq.com/5007.

Ray at home

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Jul 19 '05 #6
Thanks.

"Ray at <%=sLocation% > [MVP]" <myfirstname at lane34 dot com> wrote in
message news:uW******** ******@TK2MSFTN GP11.phx.gbl...
You have leading spaces.

strSQL= "UPDATE ProjectAddress SET PA_strOrderNumb er= ' " &
Session("PA_str OrderNumber") & " ', "
--------------------------------------------------------^

strSQL=strSQL & "PA_strQuotatio nRef= ' " & Session("PA_str QuotationRef") & " ', "
---------------------------------------^

Ray at home

"Dominic Marsat" <djmarsatAThotm ail.com> wrote in message
news:um******** ******@TK2MSFTN GP11.phx.gbl...
Here is the UPDATE code. I've sent the whole function instead of editing
bits out. I've noticed that I haven't set the strSQL string to " " as I have
done in the INSERT function, however this shouldn't matter because the

first
line of the function effectively does this. Thanks, Dom

' Update the project address database records
Function UPDATE_PA()
strSQL= "UPDATE ProjectAddress SET PA_strOrderNumb er= ' " &
Session("PA_str OrderNumber") & " ', "
strSQL=strSQL & "PA_strQuotatio nRef= ' " & Session("PA_str QuotationRef") &
" ', "
strSQL=strSQL & "PA_strProjectS tatus= ' " &
Session("PA_str ProjectStatus") & " ', "
strSQL=strSQL & "PA_strAddress1 = '" & Session("PA_str Address1") & "', "
strSQL=strSQL & "PA_strAddress2 ='" & Session("PA_str Address2") & "', "
strSQL=strSQL & "PA_strAddress3 = '" & Session("PA_str Address3") & "', "
strSQL=strSQL & "PA_strAddress4 = '" & Session("PA_str Address4") & "', "
strSQL=strSQL & "PA_strCity = '" & Session("PA_str City") & "', "
strSQL=strSQL & "PA_strCoun ty= '" & Session("PA_str County") & "', "
strSQL=strSQL & "PA_strPostCode = '" & Session("PA_str PostCode") & "' "
strSQL=strSQL & "WHERE ID=" & Session("ID")
Connection.Exec ute strSQL, lngRecsAffected , adCmdText Or

adExecuteNoReco rds
End Function
"Ray at <%=sLocation% > [MVP]" <myfirstname at lane34 dot com> wrote in
message news:eN******** *****@TK2MSFTNG P10.phx.gbl...

"Dominic Marsat" <dj******@hotma il.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..

> The editing code is identical apart from the data is retrieved using a > recordset, modified via a web form and then inserted back into the
> database using an identical expression to the INSERT statement except > with UPDATE.

You said that when the data is INSERTed, it is fine. And it's only
not fine
when you UPDATE it. So, please post the UPDATE code, not the INSERT

code!
Also, please see www.aspfaq.com/5007.

Ray at home

>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11635
by: Jan Bols | last post by:
Whenever I execute TRIM(' ')in a stored procedure or trigger, I get an ORA-03113 error. I have an oracle db 8.1.7.0.1 Enterprise edition installed on a linux-Mandrake 9.1. EXEMPLE: I created the function IS_NULL which returns 1 or 0 if the parameter is empty or not:
3
1734
by: mhk | last post by:
Hi, i used Trim(my_val) and its giving error in JavaScript. is it a correct way to trim. Please suggest me, thanks in advance.
8
2131
by: sengkok | last post by:
I have develop a smart card device reading and writing program, but I am facing a problem that when I read the value from the smart card, I get "A19\0 \0\0\0", (actually I have store the value A19 into the card from sector 17 to sector 24, 8 bytes long), I try to use Trim () function to cut the unnecessary variable to get back the value A19,...
7
4211
by: Sascha Herpers | last post by:
Hi, what is the difference between the trim function and the trim String-member? As far as I see it, both return the trimmed string and leave the original string unaltered. Is any of the two faster? Is there a general rule/opinion to prefere members over functions? Thanks for any hint.
5
15001
by: Dat K. AU DUONG | last post by:
Hi, C# Annoying string function or Am I doing Something wrong? In VB6/VB.NET I can code like: value = value.trim() and it just work!
4
9744
by: ramaswamynanda | last post by:
Hello All, I have developed an application using Ms Access 2000. My client has Access 2003. I shipped him the code yesterday and he got an error hile running the application via the mdb file itself. The line of code is If Trim(EmployeeName) <> "" And Trim(EmployerName) <> "" Then The "trim" function is highlighted and the msgbox says ...
12
1400
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM? ----------------------------------------------------------------------- Using Regular Expressions (JavaScript 1.2/JScript 3+) : String.prototype.lTrim = function() { return this.replace(/^\s+/,'');
5
3514
by: Marjeta | last post by:
I'm trying to very that the user actually entered something in the form, and not just spaces. I guess the problem is in the first line of isBlank() function. I've tried the following: elem.value.trim(); elem.value=elem.value.trim(); elem.value=trim(elem.value); elem.value.replace(/^\s+|\s+$/g,"");and none works. It correctly gives me an...
8
2834
by: Kevin Smith | last post by:
Hi, According to the intellisense help, string.Trim() "Removes all occurances or white space characters from the beginning and end of this instance." However, the follow code does not appear to modify s. s.Trim('\r'); While the follow code DOES modify s.
8
3243
by: Keith Thompson | last post by:
Kevin Smith <no@spam.comwrites: You posted this to microsoft.public.dotnet.languages.csharp, where I presume it's topical. Why on Earth did you redirect followups to comp.lang.c? Anyone else replying to Kevin Smith's article, please *ignore* the Followup-To header and post only to the csharp group. Thanks.
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.