Insert Repeater rows to Database using Entity Framework in ASP.Net

Last Reply one month ago By Andrea

Posted one month ago

hello 

 

i'm trying to insert multiple repeater rows into database but i failed todo that. 

this what i'm trying to do:

 

 

foreach (RepeaterItem item in Repeater1.Items)
        {
            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
            {
                Label lblItemNo = (Label)item.FindControl("lblItemNo");
                Label lblCampCode = (Label)item.FindControl("lblCampCode");
                Label lblUom = (Label)item.FindControl("lblUom");
                Label lblBalUnits = (Label)item.FindControl("lblBalUnits");
                Label lblWT = (Label)item.FindControl("lblWt");
                //TextBox txtExitUnits = (TextBox)item.FindControl("txtExitUnits");
                Label lblExitUnits = (Label)item.FindControl("lblExitUnits");
                
                
                Label lblcode = (Label)item.FindControl("lblCode");
                HiddenField hfcode = (HiddenField)item.FindControl("hfCustomerId");
                TempExit temp = new TempExit();

                temp.tmex_itemno = lblItemNo.Text;
                temp.tmex_gooddesc = lblCampCode.Text;
                temp.tmex_UOM = lblUom.Text;
                temp.tmex_wtbalance = decimal.Parse(lblWT.Text);
                temp.tmex_unitsbalance = decimal.Parse(lblBalUnits.Text);
                temp.tmex_ExitUnits = decimal.Parse(lblExitUnits.Text);
                db.TempExits.Add(temp);
                db.SaveChanges();
                //Response.Redirect("sendingaspx.aspx");
            }
        }

but i got the following error:

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

 

can any one help me?

You are viewing reply posted by: Andrea one month ago.
Posted one month ago
Hi @fares,
Please try the following

[Solved] Insert GridView data to Database using Entity Framework in ASP.Net

It might help you.

Cheers Andrea.
I agree, here is the link: http://e-iceblue.com/free-api