[英]Insert data into a SQLite DB using LINQ to SQL
I need to take some text fields and insert that data into a SQLite DB using LINQ to SQL. 我需要使用一些文本字段,然后使用LINQ to SQL将数据插入到SQLite数据库中。 This is what I have so far:
这是我到目前为止的内容:
var ordersDB = new SQLite.SQLiteConnection(orderPath);
Orders ord = new Orders();
ord.custNum = tblCustomerNumber.Text;
ord.itemNum = tbxEnterItem.Text;
ord.itemQty = tbxQty.Text;
There are some pretty good examples here: 这里有一些很好的例子:
http://www.codeproject.com/Articles/236918/Using-SQLite-embedded-database-with-entity-framewo http://www.devart.com/dotconnect/sqlite/articles/tutorial_linq.html http://vijayt.com/Post/Using-SQLite-database-in-NET-with-LINQ-to-SQL- http://www.codeproject.com/Articles/236918/Using-SQLite-embedded-database-with-entity-framewo http://www.devart.com/dotconnect/sqlite/articles/tutorial_linq.html http:// vijayt.com/Post/在LINQ中使用SQLite-database-net-in-SQL-
You might look into using EntityFramework , which makes things very easy. 您可能会考虑使用EntityFramework ,这使事情变得非常容易。
This is how I got it working: 这就是我的工作方式:
var ordersDB = new SQLite.SQLiteConnection(orderPath);
Orders ord = new Orders();
ord.custNum = tblCustomerNumber.Text;
ord.itemNum = tbxEnterItem.Text;
ord.itemQty = tbxQty.Text;
ord.itemDesc = tblOrderItemDesc.Text;
ord.itemCost = tblOrderItemCost.Text;
ord.orderDate = DateTime.Now.ToString();
ordersDB.BeginTransaction();
ordersDB.Insert(ord);
ordersDB.Commit();
ordersDB.Dispose();
ordersDB.Close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.