472,093 Members | 2,537 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,093 software developers and data experts.

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 2135
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 leo001 | last post: by

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.