我如何...如何通过采用文本框ID来编写插入语句 [英] How do I...how to write insert statement by taking textbox id

查看:114
本文介绍了我如何...如何通过采用文本框ID来编写插入语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张桌子 TemplateField OptionFieldValues





TemplateField

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



OptionFieldValues

OptionFieldValuesId OptionId TemplateFieldId    OptionSpecficFieldId    OptionFieldValues
1                        1          1                null                  20%





在第一个表中,我存储了表示层的字段名称和字段类型。使用MVC。



在第二个表格中,我想在按下保存按钮时插入相应字段ID的值。



如何在此处编写插入代码?



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?

推荐答案

您好,首先在表格中保存适当的值模板字段。之后取了那个id并将它传递给表 OptionFieldValues



这里我将发布一个例子,在下面的代码中我先插入表地址中的学生的地址详细信息,在学生表地址ID 之后使用 SaveChanges()





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()


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");
        }


这篇关于我如何...如何通过采用文本框ID来编写插入语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆