C#LINQ我没有将格式datetime保存到sqlserver [英] C# LINQ I don't save format datetime to sqlserver
问题描述
我没有将日期时间保存到sqlServer
sqlServer中的当前结果2012-08-24 00:00:00:000
但是我想要结果格式在Sqlserver中的时间当前为 2012-08-24 14 :25:50:789
private void Invoice_Load ( object sender , EventArgs e ) { txtTimeCurrent 。 文本 = 系统 。 DateTime 。 现在 。 ToString ();
var tbl_inv =来自db.tbl_AsInvoices中的inv
select new {
&n&n; inv.AsInvMDate
};
}
private void btSave_Click ( 对象 发件人 , EventArgs e )  
{
    tbl_AsInvoice inv = new tbl_AsInvoice ();
  inv 。 AsInvMDate = Convert 。 ToDateTime ( txtTimeCurrent 。 文字 );
using ( TransactionScope ts = new TransactionScope ())
{
db 。 tbl_AsInvoices 。 InsertOnSubmit ( inv );
db 。 SubmitChanges ();
ts 。 完整 ();
}
}
感谢您帮助我:)
Hi TooNStyle;
如果代码的这一部分txtTimeCurrent.Text仅包含没有时间组件的日期,则时间将设置为00:00:00 :000。
跨度> 跨度>
I don't save datetime to sqlServer
Result Current in sqlServer 2012-08-24 00:00:00:000
But I want result Format Time Current in Sqlserver is 2012-08-24 14:25:50:789
private void Invoice_Load(object sender, EventArgs e)
var tbl_inv = from inv in db.tbl_AsInvoices
{
txtTimeCurrent.Text = System.DateTime.Now.ToString();
select new
{
inv.AsInvMDate
};}
private void btSave_Click(object sender, EventArgs e)
{
tbl_AsInvoice inv = new tbl_AsInvoice();
inv.AsInvMDate = Convert.ToDateTime(txtTimeCurrent.Text);
using (TransactionScope ts = new TransactionScope())
{
db.tbl_AsInvoices.InsertOnSubmit(inv);
db.SubmitChanges();
ts.Complete();
}
}
Thank for help me :)
Hi TooNStyle;
If this part of the code, txtTimeCurrent.Text, only contains a date with no time component then the time will be set to 00:00:00:000.
这篇关于C#LINQ我没有将格式datetime保存到sqlserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!