By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,275 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,275 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
Roy
doh!!

Yeah, that was it. Thanks Qwert!

Nov 21 '05 #3

P: n/a

"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

P: n/a
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.