简体   繁体   English

从c#插入毫秒到mysql

[英]inserting millisecond into mysql from c#

I am trying to insert millisecond into data type of datetime(6) in MySQL using c#. 我试图使用c#在MySQL中将毫秒插入到datetime(6)的数据类型中。

here is my code: 这是我的代码:

 MySqlCommand myCommand4 = new MySqlCommand("Insert into Test_OrderRecord values('" + OrderID + "','" + customerCode + "','" + customer + "','" + TelComboBox.Text + "','" + LicenseComboBox.Text + "','" +
                          DriverComboBox.Text + "','" + AddressComboBox.Text + "','" + LocationTypeComboBox.Text + "','" + PickupComboBox.Text + "','" + CustomerTypeLabel.Text + "','" +
                       Convert.ToDecimal(TotalPriceLabel.Text) + "','" + status + "','" + note + "','" + sandReceiptNo + "','" + createtiming + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')", myConnection);
                    myCommand4.ExecuteNonQuery();

the createtiming is created with createtiming与创建

createtiming = OrderDateTimePicker.Value.ToString("yyyy-MM-dd HH:mm:ss:ffffff");

I have read the value of createtiming before it inserts into MySQL, and it does contain milliseconds, however, when I do 我已经在插入到MySQL之前读取了createtiming的值,并且它确实包含毫秒,但是,当我这样做时

SELECT * FROM SaveFundDevelopmentDB.Test_OrderDetails

on MySQL, I only see time like 在MySQL上,我只看到时间

2015-08-27 15:33:04.000000 

While the time should be like 2015-08-27 15:33:04.123456 something like this. 虽然时间应该像2015-08-27 15:33:04.123456这样的东西。

I am trying to Order the table by using this createtiming to the very millisecond. 我试图通过使用这个创建到非常毫秒的顺序来createtiming表。

How should I get this done? 我该怎么办呢?

check out this tutorial with parameterized queries. 使用参数化查询查看教程。
1. Ceate a command object : 1. Ceate命令对象:

MySqlCommand cmd = new MySqlCommand();
  1. Set the command text with parameters similar to one in the tutorial. 使用与教程中的参数类似的参数设置命令文本。
  2. Define a parameter : 定义参数:
    MySqlParameter dt = new MySqlParameter(); dt.ParameterName = "@createTiming"; dt.MySqlDbType = MySqlDbType.DateTime;<br> dt.Value = "2015-08-27 15:33:04.123456";<br> cmd.Parameters.Add(dt);

  3. Call cmd.ExecuteNonQuery(); 调用cmd.ExecuteNonQuery();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM