C# 如何在MySQL C中插入值#
我在C#中做了一些计算,我想将该值插入MySql数据库。示例totalPrice=价格1+价格2;我想把总价传给我的桌子。如何操作?您需要使用C# 如何在MySQL C中插入值#,c#,mysql,.net,sql,text,C#,Mysql,.net,Sql,Text,我在C#中做了一些计算,我想将该值插入MySql数据库。示例totalPrice=价格1+价格2;我想把总价传给我的桌子。如何操作?您需要使用INSERT语句。最好使用参数化查询,而不仅仅是INSERT命令 MySqlCommand command = new MySqlCommand(); string sql = "INSERT INTO YourTable (TotalPrice) VALUES (@TotalPrice)"; command.Parameters.AddWithValue
INSERT
语句。最好使用参数化查询,而不仅仅是INSERT
命令
MySqlCommand command = new MySqlCommand();
string sql = "INSERT INTO YourTable (TotalPrice) VALUES (@TotalPrice)";
command.Parameters.AddWithValue("@TotalPrice", totalPrice);
然后记得执行查询
command.ExecuteNonQuery()
您需要使用INSERT
语句。最好使用参数化查询,而不仅仅是INSERT
命令
MySqlCommand command = new MySqlCommand();
string sql = "INSERT INTO YourTable (TotalPrice) VALUES (@TotalPrice)";
command.Parameters.AddWithValue("@TotalPrice", totalPrice);
然后记得执行查询
command.ExecuteNonQuery()
如果您正在使用EntityFramework
yourTable obj = new yourTable();
obj.name = "name";
obj.created = DateTime.Now;
etc.......
ctx.yourTable.Add(obj);
ctx.SaveChanges();
或
如果您正在使用EntityFramework
yourTable obj = new yourTable();
obj.name = "name";
obj.created = DateTime.Now;
etc.......
ctx.yourTable.Add(obj);
ctx.SaveChanges();
或
您可以在INSERT语句中将其作为参数传递。是的……我希望将其作为十进制传递。可能吗?在INSERT语句中作为参数传递。是的…我想作为十进制传递。是否可能?+1用于参数化查询。使用它们不会有太大的压力+1用于参数化查询。使用它们不会有太大的压力!