linq insert not work
I have this code:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
using (mesteriEntities myEntities = new mesteriEntities())
{
var usern = Session["New"];
var UserID = (from Users in myEntities.Users
开发者_如何学运维 where Users.UserName == usern
select Users.UserID).SingleOrDefault();
var cati = Convert.ToInt32(DropDownList1.SelectedValue);
Job newJob = new Job();
newJob.categID = cati;
newJob.userID = UserID;
myEntities.AddToJobs(newJob);
}
}
}
When I select a combo it should add the value of combo and the userID in the Jobs table both INT values. The variables "cati" and "userid" have values.
I don't know what I should change in order to make the insert work.
Adding myEntities.SaveChanges()
after your myEntities.AddToJobs(newJob)
call should work.
Here's the relevant documentation.
精彩评论