Learn12 Learn12 - 1 year ago 89
ASP.NET (C#) Question

Executing a stored procedure on a ASP.net page

I have created a popup for guests on my website so when they complete their order, they will be redirected to a confirmation/receipt page. At that point, since they are checking out as a guest and have not created an account, the popup will show asking them to enter in a password if they choose too. This way they can login with their email and password.

I have created a stored procedure in SQL Server that looks for their customer ID and updates their password field.

My question is how do I call that procedure and attach it to the form on my website so that it will update the password? I'm not sure which way to go about it and I want to avoid SQL injection.

Answer Source

Add "ADO.NET Entity Data Model" to your project using the Add New Item menu to a project.

Generate a EF Designer from database like enter image description here

Connect to the Database enter image description here

Import the desired SP from your database enter image description here

Here is the generated Model enter image description here

If you open the Context you will see the code for the SP

If you make any changes to the SP or model, just right click the .EDMX file and use the "Update From Database" option to refresh or add new Tables or SP

P.S. You need to install EntityFramework

Good luck

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download