How Do I insert Data in a table From the Model MVC?
Posted
by user54197
on Stack Overflow
See other posts from Stack Overflow
or by user54197
Published on 2010-04-01T20:27:21Z
Indexed on
2010/04/02
9:43 UTC
Read the original article
Hit count: 280
I have data coming into my Model, how do I setup to insert the data in a table?
public string Name { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
public Info()
{
using (SqlConnection connect = new SqlConnection(connections))
{
string query = "Insert Into Personnel_Data (Name, StreetAddress, City, State, Zip, HomePhone, WorkPhone)" +
"Values('" + Name + "','" + Address + "','" + City + "','" + State + "','" + Zip + "','" + ContactHPhone + "','" + ContactWPhone + "')";
SqlCommand command = new SqlCommand(query, connect);
connect.Open();
command.ExecuteNonQuery();
}
}
The Name, Address, City, and so on is null when the query is being run. How do I set this up?
© Stack Overflow or respective owner