0

我在 C# 中做了一些计算,我想将该值插入 MySql 数据库。示例 totalPrice= Price1+Price2; 我想将 totalPrice 传递到我的表中。怎么做?

4

2 回答 2

5

You need to use an INSERT statement. It's probably best to use parameterized queries rather than just an INSERT command.

MySqlCommand command = new MySqlCommand();
string sql = "INSERT INTO YourTable (TotalPrice) VALUES (@TotalPrice)";
command.Parameters.AddWithValue("@TotalPrice", totalPrice);

Then remember to execute your query. command.ExecuteNonQuery();

于 2013-07-23T08:02:07.087 回答
0

如果您使用的是 EntityFramework...

yourTable obj = new yourTable();
obj.name = "name";
obj.created = DateTime.Now;
etc.......
ctx.yourTable.Add(obj);
ctx.SaveChanges();

或者

ctx.Database.ExecuteSqlCommand("Insert intoy YourTable values etc..");
于 2013-08-07T15:21:15.520 回答