0

我无法将我的时间组件保存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

4

1 回答 1

2

改变你的陈述:

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

至:

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

您当前Date只保存部分,您需要保存完整DateTime

于 2012-08-28T04:47:34.927 回答