我想将一堆变量的值插入数据库,我该怎么做?
我有这段代码,但无法弄清楚如何使用变量。
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();
}
答案 0 :(得分:2)
private void button2_Click(object sender, EventArgs e)
{
string myCreator = CreatorTextBox.Text;
string myProduct = ProductTextBox.Text;
int myQty = QuantityEdit.Value;
//....more vars...
var t = new ASH_PROD_ORDERS
{
Creator = myCreator,
Product = myProduct,
Qty = myQty,
//... more 'Property = var' lines
};
context.ASH_PROD_ORDERS.Add(t);
context.SaveChanges();
}