Reputation: 21
I have do some calculation in C# and i want insert that value to MySql database. Example totalPrice= Price1+Price2; I want pass the totalPrice into my table. How to do that?
Upvotes: 0
Views: 110
Reputation: 171
If you are using EntityFramework...
yourTable obj = new yourTable();
obj.name = "name";
obj.created = DateTime.Now;
etc.......
ctx.yourTable.Add(obj);
ctx.SaveChanges();
or
ctx.Database.ExecuteSqlCommand("Insert intoy YourTable values etc..");
Upvotes: 0
Reputation: 70728
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()
;
Upvotes: 5