如何从C#.net中的数据库中获取datetimepicker中的datetime数据? [英] How to fetch datetime data in datetimepicker from database in C# .net?

查看:106
本文介绍了如何从C#.net中的数据库中获取datetimepicker中的datetime数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从C#.net中的数据库中获取datetimepicker中的datetime数据?

How to fetch datetime data in datetimepicker from database in C# .net?

推荐答案

尝试:
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myDate) VALUES (@DATE)", con))
        {
        com.Parameters.AddWithValue("@DATE", myDateTimePicker.Value);
        com.ExecuteNonQuery();
        }
    }


看看:

Have a look:
String connectionString = @"Your connection string";
SqlConnection thisConnection = new SqlConnection(connectionString);

try
{
  thisConnection.Open();

  String thisQuery = "INSERT INTO ProjectList (Date) VALUES ('"+dtpDate.Value.Date+"')";
  SqlCommand thisCommand = new SqlCommand(thisQuery, thisConnection);

  thisCommand.ExecuteNonQuery();
  thisConnection.Close();
}
catch (SqlException e)
{
  Console.WriteLine(e.Message);
}


数据库中的datetime与datetimepicker.value具有相同的返回值



例如:



datetime in database has same return value with datetimepicker.value

example :

var s = (from x in ent.Flights select x).FirstOrDefault();
dateTimePicker1.Value = s.FlightDate;





这将使用来自表Flight



this will set datetimepicker1 value with flightdate from table Flight

<的flightdate设置datetimepicker1值BR />


这篇关于如何从C#.net中的数据库中获取datetimepicker中的datetime数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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