Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: Server.UrlEncode(); Problems

Results 1 to 6 of 6
Share This Thread →
  1. #1
    silencer01 is offline Contributing User
    Join Date
    Aug 2004
    Location
    London
    Posts
    40
    Rep Power
    10

    Server.UrlEncode(); Problems

    Hi All,

    I having problems with Server.UrlEncode(); I'm trying to output data from the Database in Url encoded format. The objRdr["name"] outputs the query fine but when i use it with UrlEncode(objRdr["name"])); it outputs the following error:

    CS1502: The best overloaded method match for 'System.Web.HttpServerUtility.UrlEncode(string)' has some invalid arguments

    Here is the code that i'm using:

    PHP Code:
    <%@ Page Language="C#" Debug="true"%>
    <%@ 
    Import Namespace="System.Data.SqlClient" %>

    <
    script language="C#" runat="server">
    //vars
    int numRecords;

        
    void Page_Load(){
        
    SqlConnection objConn = new SqlConnection("Server=(local); " +
            
    "Database=Database; User ID=sa; Password=password; Trusted_Connection=False");
        
    SqlCommand objCmd = new SqlCommand("SELECT * FROM tbl_maze"objConn);
        
    objConn.Open();
        
    SqlDataReader objRdr objCmd.ExecuteReader();
        
    Response.ContentType "text/plain";
        
        while (
    objRdr.Read()) {         
            
    numRecords numRecords 1;
            
    Response.Write("&name_" numRecords "=");
            
    Response.Write(Server.UrlEncode(objRdr["name"]));
            
    Response.Write("&score_" numRecords "=");
            
    Response.Write(objRdr["score"]);
        }
        
    objRdr.Close();
        
    objConn.Close();
    }
    </script> 
    Thanks,

    Jake

  2. #2
    kboek's Avatar
    kboek is offline Consuming Human
    Join Date
    Nov 2003
    Location
    Norway
    Posts
    883
    Rep Power
    127
    Could be something the value of objRdr["name"] that causes this error; try using a text like Server.UrlEncode("try>this"); and see if it raises the same error.
    Solutions brought to you by Raskenlund ICT & Media

  3. #3
    silencer01 is offline Contributing User
    Join Date
    Aug 2004
    Location
    London
    Posts
    40
    Rep Power
    10
    I tried Server.UrlEncode("try>this"); and it works fine (without an error). I can also output the database variable with the following code and it works fine.

    Response.Write(objRdr["name"]);

  4. #4
    kboek's Avatar
    kboek is offline Consuming Human
    Join Date
    Nov 2003
    Location
    Norway
    Posts
    883
    Rep Power
    127
    and what about
    Code:
    string Test = objRdr["name"];
    string Test2 = Server.UrlEncode(Test);
    Response.Write (Test2);

  5. #5
    silencer01 is offline Contributing User
    Join Date
    Aug 2004
    Location
    London
    Posts
    40
    Rep Power
    10
    Thanks kboek,

    I have tried that the recieved the following error:

    Cannot implicitly convert type 'object' to 'string'

    I guess this was the original problem. What is the best was to convert an object to a string?

    Thanks,

  6. #6
    silencer01 is offline Contributing User
    Join Date
    Aug 2004
    Location
    London
    Posts
    40
    Rep Power
    10
    I have found a resolution. Here is the code:

    string dbString1 = (string)objRdr["name"];
    Response.Write(Server.UrlEncode(dbString1));

    Please let me know if you know of a better way of doing this.

    Thanks for your help.

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

  1. Replies: 28
    Last Post: July 5th, 2005, 02:26 AM
  2. Problems Comparing dates between database / ASP
    By Pluto in forum ASP Development
    Replies: 1
    Last Post: June 7th, 2005, 11:14 AM
  3. Shopping Cart/Inventory Problems!!
    By K4tz in forum ASP Development
    Replies: 1
    Last Post: April 8th, 2005, 08:17 AM
  4. Replies: 1
    Last Post: August 6th, 2004, 02:39 PM
  5. Duplicate data entry raise problems..help pls
    By shanny in forum Microsoft Access Help
    Replies: 1
    Last Post: April 22nd, 2004, 10:55 AM

ASP Free Advertisers and Affiliates