Very new to this. I have the .aspx code basically done. I know the data source connection info, just trying to run and display output of a stored procedure on page load. This will be a report that simply displays the results upon selecting that item from a list and upon the page load. Apologies for the neandrethal'ish understanding of this...
I have been researching just the call of a stored procedure upon page load in the .aspx.cs file.
Ok, the general steps are:
First, setup a connection to SQL server.
So, in the project folder, you want to create a connection. This will thus result in ONE location for your connection, and thus you avoid multiple connections all over the place in the application.
This resulting database connection can thus be used over and over.
So, project - > properties.
Then choose the settings tab.
So, we create the database connection like this:
Note that I "often" use "." (dot) for the server name, as then you don't need to enter the database server name.
Ok, so now we have a valid connection.
So, now, here is our stored procedure, and it allows us to pass the city name to the procedure to return a list of hotels based on a given city parameter.
So, then this stored procedure:
Ok, so now our markup for the web page. We will use a GridView to display the results.
So, now our code in the page load event.
Do keep in mind that for any and all button clicks on a page, then the Page load event will fire each time. Thus, in near all cases, you want such loading code to only run on the real first page load.
Hence, we test/check the built in IsPostBack flag, and ONLY pull the data on the first real page load.
Hence this code:
And the result is then this: