Save data to SQL DB using a class in C#
asp.net, c#, visual-studio-2010
Solution
There are a number of different ways to save information to a database using C#. Some of the more common:
- ADO.NET
- Linq-To-SQL
- Entity Framework
You will probably need to read up on those to find the best one for you. If you want something quick and relatively easy, I would probably go with ADO.NET but others may disagree.
As far as how to include the code for the update in your class you could just add an `Update()` or `Save()` function.
Problem
Sorry If I am posting this question in the wrong forum. This is my first time posting at Stackoverflow. And Also I am learning ASP.NET and C# by myself so pardon me if this elementary. I have created a class file in ASP.NET 4.0 C# using visual studio 2010. My code is like below ``` namespace My.Customers { public class EmailMailingList { #region members private string _emailList; #endregion #region properties /// <summary> /// gets or sets Customer Email for Mailing List /// </summary> public string EmailList { get { return _emailList; } set { _emailList = value; } } #endregion } } ``` I have a Database table in SQL 2008 named MailingList with 2 fields namely Id and Email where Id is int with auto increment and Email Varchar(50). I also created a Stored Procedure based on this table to enter the email address. where I am getting confused is How can I add this info to my class file so the data can be saved to the database. I also created a web form called Join-Mailing-List.aspx with a textbox called tbEmail and a Submit Button called Join. What I am trying to is when someone enters the email address in the textbox I want to pass the textbox value to string EmailList in my class file and save the data to the database. I know how to pass the textbox value to my class file. I just dont know how to save the info to the DB without using the DB code in the aspx page Thanks and really appreciate for any advice or examples