Saturday, February 25, 2012

cmd.Parameters question?

I have several parameters that are passed to a stored procedure. One of them is a website URL. How can I strip out the http:// if it exists from the value before it is passed to the SP? Can the removal be handled in the cmd. statement in the code behind?

SqlConnection con3 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString3"].ConnectionString);
SqlCommand cmd3 = new SqlCommand("AdminStoresStudiosLinkSubmit", con3);
cmd3.CommandType = CommandType.StoredProcedure;
cmd3.Parameters.AddWithValue("@.SL_Name", L_Name);
cmd3.Parameters.AddWithValue("@.L_URL", L_URL);

L_URL =http://www.homepage.com and want onlywww.homepage.com to be passed into database.

Thank you,

Use the Replace command e.g. L_URL.Replace("http://", "")

|||

How would that be embedded in -cmd3.Parameters.AddWithValue("@.SL_URL", SL_URL);

thank you

|||

Below is how I initially assign the parameter value. How would I Replace the http:// at this stage?

string SL_URL = tbx_SL_URL.Text;

|||I see it now - different from classic asp -

string L_URL = tbxL_URL.Text;

L_URL = L_URL.Replace("http://","");

thank you

|||

Consider that a URL may begin with other schemes. So, is it good enough to just replacehttp:// or do you needhttps:// andftp:// andssh:// etc... ? If so, you'll want to remove*:// which could be done with well crafted regular expression (in your favorite .Net language of choice).

No comments:

Post a Comment