Link to home
Start Free TrialLog in
Avatar of aspnet-scotland
aspnet-scotlandFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How do I reference my database column within a url string in C#?

Hi,

Within the iteminserting event of my listview control I am attempting to redirect the user to a web page that is being pre-populated by a query string variable (customer_id) from my backend db.

I am using the attached C# code on my calling page but I get the error:

"System.Web.Query.Dynamic.ParseException: Operator '=' incompatible with operand types 'Int32' and 'Object"???

Any help appreciated.

Thanks.
protected void lvTrustAccounts_ItemInserting(object sender, ListViewInsertEventArgs e) 
    { 
        var customerID = e.Values["customer_id"]; 
        //Convert.ToInt32(customerID); 
         
        Response.Redirect("http://www.tradeselector.co.uk/customerTrades.aspx?trustid=" + customerID + ""); 
    }

Open in new window

Avatar of Gary Davis
Gary Davis
Flag of United States of America image

The var customerID is probably an object that should be a string (use e.Values["customer_id"].ToString()).
You should also UrlEncode the querystring parameter for safety (Server.UrlEncode(customerID)).
Gary Davis
You are using
var customerID = e.Values["customer_id"];

in this the e.Values["customer_id"] is of object type and in customerID field you want ant Int32 type value so write the statement as var customerID = Convert.ToInt32(e.Values["customer_id"].ToString());
ASKER CERTIFIED SOLUTION
Avatar of rajeeshmca
rajeeshmca
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
rajeeshmca is correct.

In addition, you may need to convert the string to an Int32 type on the receving page (assuming cutomer_id is an int32).
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aspnet-scotland

ASKER

gardavis,

Don't you mean...

Response.Redirect("http://www.tradeselector.co.uk/customerTrades.aspx?trustid=Server.UrlEncode(" + customerID + ")");

Your suggestion doesn't seem to be able to pick up Server.UrlEncode??

Thanks.
actually ignore my previous question, I was being stupid....thanks!