I surfed on the web the hole day and didn't find anything that would work on my problem :(
On my first page I got a list with all the news titles... now i want to display a few more details on that specific news by clicking on the topic and it should be open on a second page. The details are all saved in a Access database... reading the database
and everything works fine.. but how do I pass variables from that first page to second, so that I can make the right sql code to get the right news.. here some code ;)
Here I'm filling the variable for passing to the next page:
yep.. ID is getting filled with "3" f.e. I got a access database connected, where the page reads all its content.. and the ID is the primary key of that DB.
that doesn't work.. i tried your code.. but when you click on the link on the test page it didn't even fill the the text after "?ID=". In the address bar stands then: http://localhost:2493/News.cshtml?ID=
But in fact when I let it the it is (<a href="\News.cshtml?ID=@thisReader["ID"]">@thisReader["Titel"]</a>) the adress bar gives me following adress:
"http://localhost:2493/News.cshtml?ID=3"
thats how i want it to be. The problem is the second page.. where i want to work with the variable (here the ID (as you can see the "3" in the adress)).
But he gives me a mistake message
Zeile 17: // Open Connection object
Zeile 18: thisConnection.Open();
Zeile 19: ID = Request.QueryString("@thisReader["ID"]");
Zeile 20: // Create SQL command object on this connection
Zeile 21: var thisCommand = thisConnection.CreateCommand();
BoEneD
Member
39 Points
23 Posts
Pass dynamic variables from one page to other
Feb 01, 2012 11:23 AM|LINK
Hey folks,
I surfed on the web the hole day and didn't find anything that would work on my problem :(
On my first page I got a list with all the news titles... now i want to display a few more details on that specific news by clicking on the topic and it should be open on a second page. The details are all saved in a Access database... reading the database and everything works fine.. but how do I pass variables from that first page to second, so that I can make the right sql code to get the right news.. here some code ;)
Here I'm filling the variable for passing to the next page:
<tr> <td width="80%"><a href="\News.cshtml?ID=@thisReader["ID"]">@thisReader["Titel"]</a></td> <td width="20%">@thisReader["Enddatum"]</td> </tr>on the second page i inserted :
@{ ID = Request.QueryString("ID"); }But now he is giving me a "CS1026: ) erwartet." compiler error.. hope somebody can help me out
Greetings Benedikt
Sum8
Contributor
4141 Points
931 Posts
Re: Pass dynamic variables from one page to other
Feb 01, 2012 11:54 AM|LINK
Are you getting any values in "@thisReader["ID"]", "@thisReader["Titel"]" and "@thisReader["Enddatum"]" ?
Sumit Pathak
------------------
ThisPost = Helped == True ? "Mark As Answer" : "Elaborate your problem in more details"
BoEneD
Member
39 Points
23 Posts
Re: Pass dynamic variables from one page to other
Feb 01, 2012 12:00 PM|LINK
yep.. ID is getting filled with "3" f.e. I got a access database connected, where the page reads all its content.. and the ID is the primary key of that DB.
Sum8
Contributor
4141 Points
931 Posts
Re: Pass dynamic variables from one page to other
Feb 01, 2012 12:08 PM|LINK
So is any value getting displayed in this:
Sumit Pathak
------------------
ThisPost = Helped == True ? "Mark As Answer" : "Elaborate your problem in more details"
BoEneD
Member
39 Points
23 Posts
Re: Pass dynamic variables from one page to other
Feb 01, 2012 01:52 PM|LINK
yep... the date is displayed... exactly the date I wrote in the database... :)
but the date isn't the important thing, the important thing is, that the variable i send to the next page, doesnt really arrive there ^^
Sum8
Contributor
4141 Points
931 Posts
Re: Pass dynamic variables from one page to other
Feb 02, 2012 04:21 AM|LINK
Ok. I was just trying to investigate whether values are getting fetched from the DB or not.
As values are getting fetched, you may try this one:
Sumit Pathak
------------------
ThisPost = Helped == True ? "Mark As Answer" : "Elaborate your problem in more details"
BoEneD
Member
39 Points
23 Posts
Re: Pass dynamic variables from one page to other
Feb 02, 2012 05:12 AM|LINK
that doesn't work.. i tried your code.. but when you click on the link on the test page it didn't even fill the the text after "?ID=". In the address bar stands then: http://localhost:2493/News.cshtml?ID=
But in fact when I let it the it is (<a href="\News.cshtml?ID=@thisReader["ID"]">@thisReader["Titel"]</a>) the adress bar gives me following adress:
"http://localhost:2493/News.cshtml?ID=3"
thats how i want it to be. The problem is the second page.. where i want to work with the variable (here the ID (as you can see the "3" in the adress)).
But he gives me a mistake message
Zeile 17: // Open Connection object Zeile 18: thisConnection.Open(); Zeile 19: ID = Request.QueryString("@thisReader["ID"]"); Zeile 20: // Create SQL command object on this connection Zeile 21: var thisCommand = thisConnection.CreateCommand();with the compiling error: CS1026: ) expected.
Sum8
Contributor
4141 Points
931 Posts
Re: Pass dynamic variables from one page to other
Feb 02, 2012 05:17 AM|LINK
Ohh, yes !! there is small mistake..
Instead of this, try below code:
ID = Request.QueryString("ID");Sumit Pathak
------------------
ThisPost = Helped == True ? "Mark As Answer" : "Elaborate your problem in more details"
BoEneD
Member
39 Points
23 Posts
Re: Pass dynamic variables from one page to other
Feb 02, 2012 05:34 AM|LINK
okay i tried, but then he told me, the variable ID is no declarated so I inserted var ID =""; but now he the compiler tells me
Compiler error: CS1955: the not available member "System.Web.HttpRequestBase.QueryString" cannot be used like a method.
I'm not quite sure, what he wants to tell me with that xD
MetalAsp.Net
All-Star
112157 Points
18249 Posts
Moderator
Re: Pass dynamic variables from one page to other
Feb 02, 2012 05:40 AM|LINK
Replace parenthesis with square brackets: ["ID"]