0

私の時間コンポーネントDATETIMEを SQL Server に保存できません。

SQL Server の現在の結果ですが、SQL Server2012-08-24 00:00:00:000の現在の時刻が必要です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 に答える