在C#中使用Time(7)DataType [英] Using Time(7) DataType in C#

查看:276
本文介绍了在C#中使用Time(7)DataType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在db表中将时间字段声明为时间(7)。如何将时间选择器中的数据插入到此,请解释是否有人知道

Hi,
I have declared a time field in db Table as Time(7). How can i insert a data from a Time picker to This, Please explain if anyone knows

推荐答案

取决于您使用的时间选择器(我不知道)您可能需要将其输出转换为TimeSpan然后传递:TimeSpan直接映射到/从SQL时间字段映射。

Depending on what time picker you use (and I have no idea) you may need to convert it's output to a TimeSpan and then pass that: TimeSpan maps directly to/from an SQL Time field.
TimeSpan theTime = DateTime.Now.TimeOfDay;
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (theTime) VALUES (@TIME)", con))
        {
        com.Parameters.AddWithValue("@TIME", theTime);
        com.ExecuteNonQuery();
        }
    }


这篇关于在C#中使用Time(7)DataType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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