Reputation: 2378
I am creating a website. It has a database and I'm trying to work with the Member
table.
On the page, I asked the user to fill out some basic information to become a member, once the submit button is clicked, I stored these information into a session object (which has MemberID
, LastName
, FirstName
, and such) I was wondering how I can store all information in this session object to the Member
table in the database? (The table has already been created)
Also, I would like to know when an existing member logs in. How can I get information from the database and display on the webpage (in case the member wants to edit his profile).
I am using Visual Studio 2010, coding in aspx, C#, and SQL database.
----- edit 8:13pm 6/17/2012 -----
I might not be clear when I first explain my problem.
I have a Member
class in the .cs file, which has those variables states above. I created a new entry for a new member (on the web page), then store the object in session.
Upvotes: 0
Views: 1366
Reputation: 18379
Personally I don't see the need to use ASP.Net session state, based on what you've said.
I presume you already have a button click handler to assign the control values of the submitted form to your Member
object, and then you assign Member
to session. But instead, this is the point at which you want to store Member
to the database and not both with session.
So pass the class instance to a method which will make use of ADO.Net. In the method create a SqlConnection object, and a SqlCommand object. There are more generalised versions but I'm assuming your using sql server. To your SqlCommand object add command text which should be an update SQL statement, and parameters. Finally execute the command to store to the database.
Working through this introduction site should explain the finer detail. http://www.csharp-station.com/Tutorial/AdoDotNet/lesson01
Reading the user information back is similar except you start to use a SqlDataReader. Again that article will help.
Of course there is something called Entity Framework Code First which takes away all the plumbing between your code and the database.
Upvotes: 2
Reputation: 26
Consider creating a data access layer and use this to persist data to the database.
Upvotes: 0