469,575 Members | 1,429 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

Compiler hates Replace() function... any ideas?

Roy
Hey all,

Created an .aspx page using VB as the code behind. Compiler pops up
error: "BC30451: Name 'Replace' is not declared." Essentially, it acts
as if Replace is a custom function that needs to be declared, not a
built in one. What gives? FWIW, the code below occurs within a sub
within a class. Thanks for any advice!
strSQLQuery = "UPDATE [lla] " _
& "SET assigned_to = N'" & Replace(assigned_to.Text, "'", "''") & "', "
_
& "assigned_dt = '" & Replace(assigned_dt.Text, "'", "''") & "', " _
& "poe_recon_done = '" & Replace(poe_recon_done.Text, "'", "''") & "',
" _
& "vdn_done = '" & Replace(vdn_done.Text, "'", "''") & "', " _
& "vdn_done_dt = '" & Replace(vdn_done_dt.Text, "'", "''") & "', " _
& "final_appvl = '" & Replace(final_appvl.Text, "'", "''") & "', " _
& "final_appvl_dt = '" & Replace(final_appvl_dt.Text, "'", "''") & "',
" _
& "carrier_web_validation = '" & Replace(carrier_wv.Text, "'", "''") &
"', " _
& "notes = N'" & Replace(notes.Text, "'", "''") & "' " _
& "WHERE ISNULL(voydoc,'') + ISNULL(poe,'') + ISNULL(pod,'') = " &
strID & ";"
BTW, my imports are:
imports System
imports System.Data
imports System.Data.SqlClient
imports System.Web
imports System.Web.UI
imports System.Web.UI.WebControls
imports System.Web.UI.HtmlControls

Nov 21 '05 #1
4 2072
Imports Microsoft.VisualBasic?

"Roy" <ro**********@gmail.com> schreef in bericht
news:11**********************@c13g2000cwb.googlegr oups.com...
Hey all,

Created an .aspx page using VB as the code behind. Compiler pops up
error: "BC30451: Name 'Replace' is not declared." Essentially, it acts
as if Replace is a custom function that needs to be declared, not a
built in one. What gives? FWIW, the code below occurs within a sub
within a class. Thanks for any advice!
strSQLQuery = "UPDATE [lla] " _
& "SET assigned_to = N'" & Replace(assigned_to.Text, "'", "''") & "', "
_
& "assigned_dt = '" & Replace(assigned_dt.Text, "'", "''") & "', " _
& "poe_recon_done = '" & Replace(poe_recon_done.Text, "'", "''") & "',
" _
& "vdn_done = '" & Replace(vdn_done.Text, "'", "''") & "', " _
& "vdn_done_dt = '" & Replace(vdn_done_dt.Text, "'", "''") & "', " _
& "final_appvl = '" & Replace(final_appvl.Text, "'", "''") & "', " _
& "final_appvl_dt = '" & Replace(final_appvl_dt.Text, "'", "''") & "',
" _
& "carrier_web_validation = '" & Replace(carrier_wv.Text, "'", "''") &
"', " _
& "notes = N'" & Replace(notes.Text, "'", "''") & "' " _
& "WHERE ISNULL(voydoc,'') + ISNULL(poe,'') + ISNULL(pod,'') = " &
strID & ";"
BTW, my imports are:
imports System
imports System.Data
imports System.Data.SqlClient
imports System.Web
imports System.Web.UI
imports System.Web.UI.WebControls
imports System.Web.UI.HtmlControls

Nov 21 '05 #2
Roy
doh!!

Yeah, that was it. Thanks Qwert!

Nov 21 '05 #3

"Roy" <ro**********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Created an .aspx page using VB as the code behind. Compiler pops up
error: "BC30451: Name 'Replace' is not declared." .. . . & "SET assigned_to = N'" & Replace(assigned_to.Text, "'", "''") & "', "

.. . .

Strings are far cleverer than they used to be - take a look at the methods
on the String Class :

.. . .
& "SET assigned_to = N'" & assigned_to.Text.Replace("'", "''") & "', "
.. . .

HTH,
Phill W.
Nov 21 '05 #4
Though there's a neater way you can do this now using String.Format and a
utility function

Function Quote(Byval val As String) As String
Return val.Replace("'", "''")
End Function

' NB Shorted update statement for clarity
strSQLQuery = "UPDATE [lla] SET assigned_to = N'{0}', assigned_dt = '{1}'
strSQLQuery = String.Format(strSQLQuery, Quote(assigned_to.Text),
Quote(assigned_dt.Text))

The other way would be to use a SqlCommand and parameters, that way you
don't have to handle the string quoting and is even more robust against SQL
injection attacks.

Regards

Paul
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

34 posts views Thread by Nikola Skoric | last post: by
2 posts views Thread by James Marshall | last post: by
13 posts views Thread by Bryan Parkoff | last post: by
3 posts views Thread by CK | last post: by
159 posts views Thread by bernard | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.