C#LINQ我没有将格式datetime保存到sqlserver [英] C# LINQ I don't save format datetime to sqlserver

查看:63
本文介绍了C#LINQ我没有将格式datetime保存到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)
   
{
    txtTimeCurrent
.Text = System.DateTime.Now.ToString();

var tbl_inv = from inv in db.tbl_AsInvoices
                         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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆