Hi all I'm trying to insert some values to the database using mvc in asp.net. I heard that it would be good use objects when inserting data. So How can I achieve this using a List of objects through properties designed in a class.
Have a class called,
public class Customer
{
public string Name { get; set; }
public string Company { get; set; }
public int Telephone { get; set; }
public string Email { get; set; }
public int Id { get; set; }
}
So I have a another class which simply do the sql commands
DBAccess.cs
public List<Customer> AddCustomers(string spName)
{
List<Customer> customers = new List<Customer>();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = spName;
}
I know that using Idata Reader using can get the values in a database like this
IDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Customer cus = new Customer();
cus.Name = reader["cus_name"].ToString();
cus.Id = Convert.ToInt32(reader["cid"]);
customers.Add(cus);
}
How do I insert data back to the database using such a scenario? Help would be appreciated.