Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I have two tables TemplateField and OptionFieldValues.


TemplateField
TemplateFieldId     FieldName   IsActive    DisplayOrder    FieldType
1                Deprication        1           1             TEXT
2                  Cash out flow    1           2             MUltivalue
3                     Cash          1           3             TEXT
4                 useful life       1           1             Text


OptionFieldValues
OptionFieldValuesId OptionId TemplateFieldId    OptionSpecficFieldId    OptionFieldValues
1                        1          1                null                  20%


In first table, i'm storing the field names and field type of the presentation layer. Using MVC.

In second table, i want to insert the values of those corresponding field id when we press the save button.

how to write a insert code here?
Posted
Updated 12-May-15 20:03pm
v3
Comments
Maciej Los 13-May-15 1:50am    
What kind of save button? What framework: WPF, WinForms, WebControls? What language: VB.NET, C#?
What have you tried? Where are you stuck?
King Fisher 13-May-15 2:00am    
He mentioned that on MVC :)
Maciej Los 13-May-15 2:03am    
I missed that, King.
King Fisher 13-May-15 2:10am    
:)
What have you tried and where is the exact issue?

1 solution

Hi, first save the appropriate values in the table Template Field. after that took that id and pass it to the Table OptionFieldValues.

Here i will post one example, In the below code first I insert the address details of student in the table Address, after that store that AddressID in the Student Table using SaveChanges()


C#
public ActionResult Create(Member m)
        {
            if (ModelState.IsValid)
            {

                var address = new Address()
                {
                    Address1 = m.Address.Address1,
                    Address2  = m.Address.Address2,
                    City=m.Address.City,
                    StateProvinceID=1,
                    CountryID=1,
                    PostalCode=m.Address.PostalCode,
                    ContactNo=m.Address.ContactNo
                };
                objMoneyManager.Addresses.Add(address);
              objMoneyManager.SaveChanges();
                int id = address.ID;
                var member = new Member()
                {
                    Name = m.Name,
                    MasterGroupID = m.MasterGroupID,
                    SubGroupID = m.SubGroupID,
                    RoleID = m.RoleID,
                    Status = m.Status,
                    AddressID=id
                };
                objMoneyManager.Members.Add(member);
                objMoneyManager.SaveChanges();
                return RedirectToAction("Index");
            }
            return RedirectToAction("Create");
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900