Yahweh Posted October 19, 2006 Share Posted October 19, 2006 This is probably an elementary problem, but my Google searches didn't reveal any good answers.I have this function for escaping SQL string: Public Function SafeSQL(strString as String) as String Return replace(strString, "'", "''", 1, -1, CompareMethod.Text)End Function I want to put that code in another file so it can be included globally on all of my pages or make it available selected pages without using the classic asp "<!--#include-->" statement, but I don't know the ASP.Net syntax. Any help would be appreciated Link to comment Share on other sites More sharing options...
jesh Posted October 19, 2006 Share Posted October 19, 2006 In C# (I don't know VB) I would do something like this: namspace UtilityFunctions{ public class SQLFunctions { public static string MakeSafe(string unsafeString) { // whatever you do to make the string safe. } }} Then, to use it in another class/page, you would do something like this: using UtilityFunctions;public class MyOtherClass{ public void DoIt(string unsafeString) { string safeString = SQLFunctions.MakeSafe(unsafeString); }} I hope this helps! Link to comment Share on other sites More sharing options...
pulpfiction Posted October 19, 2006 Share Posted October 19, 2006 In VB.NET Namespace Utilities Public Class SQLFunctions Public Shared Function MakeSafe(Byval str as String) 'Code goes here End Function End ClassEnd Namespace To call this function.... Imports UtilitiesDim unsafe as StringDim safe as String safe = SQLFunctions.MakeSafe(unsafe) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now