I would like to create code within my aspx document to query data from a database. I also want to update data in a database based on user input from a form. I would like examples of code that does this inline as opposed to using the code-behind model. I'd like to use SQL and a datareader to put data into a HTML table. I would also like to put user inputted form values to place in a SQL update query. I recognize that is not the ideal method to doing this and may be a bit outdated. Can anyone provide an example?
Thanks

Dipal ChoksiRank #199 · 12K reputationPosted May 12, 2008, 8:22 PM EDT
It might get easier if you factor the data access code into one or more functions in your aspx file if you have to use sqldatareader and inline code. You can consider reading the data from the sqldatareader into an in-memory object and closing the sqldatareader first, in order to free up the data connection. Out of curiosity, is there any particular reason for your choice of design?
Sorry no code snippet included here at this time...
Craig20 reputationPosted May 13, 2008, 4:16 AM EDT
Thanks for the response.
I'm new to ASP/ASP.net, relatively new to C# and fairly fluent in scripting language called ODBiC so I want to go with what I know. Also I have limited access to the web server- it is on computer where my access rights are restricted - so compiling code behind the aspx file might be tricky. I suppose there is a way I can do this from my machine remotely using visual studio (front page server extensions are not installed in IIS and may not be in the near future) or I can compile the code manually using csc.exe ...I just do not know how. I figure if I write all of my code within the aspx file I do not have to worry about compiling it. I've had success in accessing and manipulating data using C# code. My question is how do I write the C# code in the aspx file and set my html controls equal to the field values in the database. My guess is that I can create code within the <%........%> block of the html that - within the page load method - creates a object that reads in the data using SQL, sets the database field values equal to c# variables, and then sets the html controls equal to c# variables.
Thanks
ArshadRank #2,492 · 564 reputationPosted May 13, 2008, 12:59 PM EDT
It will give you that page what ever u had done into the Page, Thanks
With Regards
Khan
Dipal ChoksiRank #199 · 12K reputationPosted May 13, 2008, 8:34 PM EDT
On the topic of compilation issues for code-behind model, if you were to copy the ASP.net files directly, the web pages will be automatically compiled when the page is called for the first time.
Craig20 reputationPosted May 14, 2008, 9:55 AM EDT
I see the trick is to include the "src=" in order to get the code behind to compile.
Thanks
<%@ Language="C#" Inherits="MyStuff.MyClass" src="MyCodebehind.cs" %>