关于datetimepicker(如何仅添加日期) [英] About datetimepicker (How to add only date )

查看:76
本文介绍了关于datetimepicker(如何仅添加日期)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位大家好,



我有Windows窗体。还有数据库。我正在输入该数据库的数据productT表。

该表有7个字段。



这些是必填字段



字段名称数据类型< br $>


MFDdate datetime



EXPdate datetime



我想使用datetimepicker在上述字段中添加日期。我使用了2个datetimepickers。



这是我试过的代码。



Hello everybody,

I have windows form.and also it has database.I'm entering data "productT" table of that database.
That table has 7 fields.

these are essential fields

field name datatype

MFDdate datetime

EXPdate datetime

I want add only date to the above fields using datetimepicker.I used 2 datetimepickers.

Here is the code I tried.

dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = "yyyy-MM-dd";
            dateTimePicker2.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
            dateTimePicker2.CustomFormat = "yyyy-MM-dd";

SqlCommand comm1 = new SqlCommand("INSERT INTO productT(MFDdate,EXPdate)Values('" +dateTimePicker1.Value.Date+"','" +dateTimePicker2.Value.Date+ "')", conn1);





我在寻找答案。这真是烦人的问题。



请帮帮我



I looking for answers.This is really annoying problem.

please help me

推荐答案

MFdate和EXPdate是日期时间列。



这意味着他们总会有时间。如果您只想使用日期部分,无论您在何处显示它,您都需要格式化DateTime以使其仅包含日期部分,但SQL将包含时间,您无法更改它。
MFdate and EXPdate are Datetime columns.

That means they will always have a time in them. If you just want to use the date part, wherever you are displaying it you need to format the DateTime so that it includes just the date portion, but the SQL will contain a time, you can't change that.


string transactionDate = drForTransInfo[8].ToString();
                        string getDate = string[] dateSplit = transactionDate.Split(' ');
                        foreach (string word in dateSplit)
                        {
                            getDate = dateSplit[0].onvert.ToDateTime(drForTransInfo[9].ToString()).ToString("hh:mm:ss tt");
                        }
                        lblDate.Text = getDate;


这篇关于关于datetimepicker(如何仅添加日期)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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