【发布时间】:2015-03-23 14:56:33
【问题描述】:
我一直在试图弄清楚如何将当前日期时间从 c# 添加到 mysql 列中,并且该属性/列也是“日期时间”格式。我正在写这段代码。
if (comboBox1.Text == "Cash On Delivery")
{
MessageBox.Show("Your order has been placed.","",MessageBoxButtons.OK);
string timeString = DateTime.Now.ToString("YYYY-MM-DD HH:MM:SS");
string constring = "datasource=localhost;port=3306;username=root;password=root";
string query = "insert into artgallery.payment_method where payment_method ='" +comboBox1.Text+ "' AND payment_date='" +formatForMySql+ "' AND payment_amount = '" +variables.total_amount+ "' ";
//rest of the code
}
我收到了一些与我试图在“payment_date”列中插入的 timeString 相关的语法错误。
【问题讨论】:
-
顺便说一下,没有
YYYY、DD和SS作为custom date and time specifiers。自定义说明符区分大小写。mm是几分钟,MM是几个月。