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

Last Reply 10 months ago By Andrea

Posted 10 months 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?

Posted 10 months 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: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html