Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 5th, 2003, 12:16 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default chr function

How can I validate the text box that If the user enters " , ' , # that I can capture these values from textbox.

Here is the my sql code but it does't work:

strSQLUpdate = "update tblCycleCount set strRootType=" & Chr(34) & sRootType & Chr(34) & ",Comment =" & Chr(34) & sTextBox & Chr(34) & " ,dDateRootCaused = " & Chr(34) & Today & Chr(34) & ",strRootCause=" & Chr(34) & sRootCause & Chr(34) & " where nID = " & aListIds(i)


I get the following error:
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 4.

Thanks,

Tulin
Reply With Quote
  #2 (permalink)  
Old December 5th, 2003, 03:12 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Well, it depends on what you're trying to do.

If you want to send the literal value of ' to the database, all you need to do is replace each occurence of ' with two ' characters. So, this example would work:

Dim UserName
Dim SQL
UserName = "O'Brien"
UserName = Replace(UserName, "'", "''")
SQL = "INSERT INTO User (Name) VALUES('" & UserName & "')"

When the value for the column is enclosed in ' characters, and each ' character in the value has been escaped, you can safely send it to the database.

Is this what you're after?

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #3 (permalink)  
Old December 5th, 2003, 05:22 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I am trying to send the input data in the textbox to database. I am having hard time to send special characters to the database. For
example I get error when I typed seq#44' in the textbox.

Thanks...
Reply With Quote
  #4 (permalink)  
Old December 5th, 2003, 05:27 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Well, with the code I showed you, this can easily be solved.

If you post a bit more of your code (i.e. part of the ASP (??) code that creates the SQL statement, and the part where you retrieve the value from the text box, I'll try to change it so you can add a ' to the database as well.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #5 (permalink)  
Old December 5th, 2003, 05:45 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the summary of the asp pages:

This is the first form:
<form name="Setup" method="post" action="CycleProcess1.asp?Type=MLS">
.
.
<TD><INPUT type="text" name="Comment_<%=nID%>" id="sComment" size="20"></TD>
.
.
</form>

This is the CycleProcess1.asp:

<form name="Set" method="post" action="CycleMain.asp?Type=Finance">

sListIds = Request("IDs")
aListIds = Split(sListIds, "," )
.
.
.
sChk ="chk_" & aListIds(i)
sChkType = Request(sChk)
.
.
set rsListCounts = Server.CreateObject("ADODB.Recordset")strListCount s = "SELECT Comment from tblCycleCount where nID = " & aListIds(i) & "
rsListCounts.Open strListCounts, oConn1
.
.
Comment = rsListCounts("Comment")
.
.
strSQLUpdate = "update tblCycleCount set Comment = '" & sTextType & "' where nID = " & aListIds(i)
oConn1.Execute(strSQLUpdate)
.
.
.
</form>

I just try to insert the special characters to the database including #,'," e.t.c
Thanks,
Reply With Quote
  #6 (permalink)  
Old December 5th, 2003, 06:00 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just can not insert ' to the database.

Thanks...

Reply With Quote
  #7 (permalink)  
Old December 5th, 2003, 06:30 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Well, it could be me, but I am having some trouble seeing the relation between page 1 and 2. I see a text box on page 1 (name="Comment_<%=nID%>") that is never used on page 2, and on page 2 I can't see the form element you use to retrieve the values from.....
So, the following code is based on some assumptions:
Code:
' Let's assume that sTextType comes from a form field
' called txtTextType. And let's assume this field 
' contains: seq#44' 

Dim sTextType
sTextType = Request.Form("txtTextType")
' sTextType now contains: seq#44'
' You'll need to escape the ' with two '':
sTextType = Replace(sTextType, "'", "''")
' sTextType now contains: seq#44''

' Having escaped the value of sTextType, you can now
' send it to the database:
strSQLUpdate = "UPDATE tblCycleCount SET Comment = '" & sTextType & "' WHERE nID = " & aListIds(i)
If aListIds(i) contains 4 for example, the UPDATE statement will now look like this:

UPDATE tblCycleCount SET Comment = 'seq#44''' WHERE nID = 4

which is perfectly legal for the database.

Does this help?

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C# equivalent function to VB chr for values > 128 relaytest49 ASP.NET 2.0 Professional 0 May 24th, 2006 10:08 AM
CHR(13) errors in CDO.CreateMHTMLBody() janaka44 Classic ASP Professional 0 April 5th, 2006 11:08 PM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
Chr$ crmpicco Excel VBA 3 April 26th, 2005 02:44 AM
syntax for storing chr(0) in sql server through vb neeraj.khattar Beginning VB 6 1 January 10th, 2005 02:20 PM



All times are GMT -4. The time now is 07:37 PM.


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