Click here to Skip to main content
15,922,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to pass int data to Id when I redirect to the page but the id is being read as string when I put it between " " and I tired the code below but I got error conversion failed when converting the varchar value to data type int

when I did it in asp.net tag it works fine



What I have tried:

Response.Redirect("View.aspx?Id="+ HttpContext.Current.Request.QueryString["MaId"].ToString());


and this also not working
Response.Redirect("View.aspx?Id="+ Eval("MaId") );
Posted
Updated 28-Jul-16 4:53am

1 solution

You have to pass it as a string, querystring params are always string. Your View.aspx page needs to convert it back to an int

C#
int id = 0;
int.TryParse(Request.QueryString["id"], out id);
 
Share this answer
 
Comments
Member 12618369 28-Jul-16 11:01am    
Thanks
please clarify more where I have to put this code in view page or the page where I write direct response
please
F-ES Sitecore 28-Jul-16 11:03am    
That code will go on the View.aspx page.
Member 12618369 28-Jul-16 11:17am    
thanks
I tried to used but not working I think because MaId is int and it is passed by id with int it works from another page I need to ckeck is the id is string or int if it is string I need to convert it before I passed to MaId
I am sorry about that
please help
cmd.CommandText = "SELECT URLVideoPath FROM Material WHERE MaId=@MaId";
// int.TryParse(Request.QueryString["id"], out id);
cmd.Parameters.AddWithValue("@MaId", id);
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{

sdr.Read();
URL = sdr["URLVideoPath"].ToString();
F-ES Sitecore 28-Jul-16 11:20am    
You'll do the int.TryParse here

int id = 0;
int.TryParse(Request.QueryString["id"], out id);
cmd.Parameters.AddWithValue("@MaId", id);
Member 12618369 28-Jul-16 11:27am    
Thanks
I got error red line under the id said id cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
I do not know what is it
please help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900