无法将 DATETIME 的时间组件保存到 SQL Server



我无法将DATETIME的时间组件保存到SQL Server。

SQL Server中的当前结果是2012-08-24 00:00:00:000,但我想要SQL Server中2012-08-24 14:25:50:789 中的当前时间

private void Invoice_Load(object sender, EventArgs e)
{
    txtTimeCurrent.Text = System.DateTime.Now.ToString();  
}
private void btSave_Click(object sender, EventArgs e)
{
    tbl_AsInvoice inv = new tbl_AsInvoice();
    inv.AsInvMDate = Convert.ToDateTime(txtTimeCurrent.Text).Date;
    using (TransactionScope ts = new TransactionScope())
    {
        db.tbl_AsInvoices.InsertOnSubmit(inv);
        db.SubmitChanges();
        ts.Complete();
    }
}

我尝试

inv.AsInvMDate = Convert.ToDateTime(txtTimeCurrent.Text);

它不起作用。T_T

更改您的声明:

inv.AsInvMDate = Convert.ToDateTime(txtTimeCurrent.Text).Date;

收件人:

inv.AsInvMDate = Convert.ToDateTime(txtTimeCurrent.Text);

您当前仅保存Date部件,需要保存完整的DateTime

最新更新