【发布时间】:2017-11-08 16:21:01
【问题描述】:
我想将一堆变量的值插入数据库,我该怎么做?
我有这段代码,但不知道如何使用变量。
private void button2_Click(object sender, EventArgs e)
{
var context = new ASH_ORDER_DBEntities();
var t = new ASH_PROD_ORDERS //Make sure you have a table called test in DB
{
Creator = "", Product = "", Created = "", Qty = "", Part_Number = "", Due = "", Edited = "", Ordered = null, Other = "", Urgent = null, Supplier = "",
};
context.ASH_PROD_ORDERS.Add(t);
context.SaveChanges();
}
【问题讨论】:
-
您能否将您的问题陈述更清楚一些?
-
首先,将 ASH_ORDER_DBEntities 包含在 using 语句中。第二:向我们展示您的课程和 EF 配置。
-
你的变量是在哪里定义的?本质上,您需要将分配给
t实例的空字符串替换为您要插入的变量的名称,但如果没有更多细节,很难说得更多。 -
我还没有定义我的变量,但它会像 var timeNow = datatime.now();等等……
-
@GustavoF
using声明是 not required 和DbContext
标签: c# entity-framework-6