Last post Feb 02, 2012 11:39 AM by BoEneD
Feb 01, 2012 12:23 PM|BoEneD|LINK
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:
<td width="80%"><a href="\News.cshtml?ID=@thisReader["ID"]">@thisReader["Titel"]</a></td>
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
Feb 01, 2012 12:54 PM|Sum8|LINK
Are you getting any values in "@thisReader["ID"]", "@thisReader["Titel"]" and "@thisReader["Enddatum"]" ?
Feb 01, 2012 01:00 PM|BoEneD|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.
Feb 01, 2012 01:08 PM|Sum8|LINK
So is any value getting displayed in this:
Feb 01, 2012 02:52 PM|BoEneD|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 ^^
Feb 02, 2012 05:21 AM|Sum8|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:
Feb 02, 2012 06:12 AM|BoEneD|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:
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.
Feb 02, 2012 06:17 AM|Sum8|LINK
ID = Request.QueryString("@thisReader["ID"]");
Ohh, yes !! there is small mistake..
Instead of this, try below code:
ID = Request.QueryString("ID");
Feb 02, 2012 06:34 AM|BoEneD|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
Feb 02, 2012 06:40 AM|MetalAsp.Net|LINK
Replace parenthesis with square brackets: ["ID"]
Feb 02, 2012 06:41 AM|Sum8|LINK
ID = Request.QueryString["ID"];
Feb 02, 2012 06:48 AM|BoEneD|LINK
okay that worked, but he instantly gave me another error.. :D i dont get it.. he tells me "no data was found for at least one essential parameter" on the line with
OleDbDataReader thisReader = thisCommand.ExecuteReader();
but this line works on the first page, why shouldnt it work on the second too?
Feb 02, 2012 07:03 AM|Sum8|LINK
Make sure you have set the SQL query for the command.
Also, try running the SQL query without WHERE clause.
Feb 02, 2012 07:11 AM|BoEneD|LINK
okay did work by removing the WHERE clause in my sql query, but with the variable (ID) I get from the first page i want in my to work in the sql query:
var thisConnection = new OleDbConnection(@"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\Users\lechner\Documents\My Web Sites\Starter Site\App_Data\Aufgaben.accdb");
var IDr = "";
// Open Connection object
IDr = Request.QueryString["ID"];
// Create SQL command object on this connection
var thisCommand = thisConnection.CreateCommand();
// Initialize SQL Select command to retrieve desired data
thisCommand.CommandText = "SELECT * FROM Aufgaben WHERE ID = IDr";
Feb 02, 2012 09:40 AM|Sum8|LINK
thisCommand.CommandText = "SELECT * FROM Aufgaben WHERE ID =" + IDr;
Feb 02, 2012 10:05 AM|BoEneD|LINK
thx!!!!!!! totally worked out! :D
Feb 02, 2012 11:30 AM|hans_v|LINK
thx!!!!!!! totally worked out!
But you're vunarable for SQL injections!!!! Read this:
Feb 02, 2012 11:39 AM|BoEneD|LINK
the page I'm working on is just for company Intranet ;) if somebody from the company is trying to hack to page, I'm personally going to rip some a****! :D