如何从数据库中检索日期格式 [英] how to retrieve date format from databade

查看:139
本文介绍了如何从数据库中检索日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从数据库中检索日期格式数据到textbox.my这里附带的代码



SqlDataReader sdr = sda.ExecuteReader()if(sda.Read()= = True)

Txtdateofbirth = sdr.GetValue(2).ToString();

但时间也显示在文本框中..如何仅在文本框中获取日期

解决方案

在ToString中使用您选择的日期格式



 Txtdateofbirth = sdr.GetValue(2).ToString(dd / MM / yyyy); 





可能需要首先施放它但是/>


 Txtdateofbirth =((DateTime)sdr.GetValue(2))。ToString(dd / MM / yyyy); 





这假设该字段存储为Date或DateTime字段,如果不存在则应该存在。


< blockquote> SqlDataAdapter sda = cmd.ExecuteReader();

while(sda.Read())

{

DateTime dt = Convert.ToDateTime (sda [DateOfBirth]);

}


How to retrieve date format data from database to textbox.my code attached here

SqlDataReader sdr=sda.ExecuteReader() if (sda.Read()==True)
Txtdateofbirth=sdr.GetValue(2).ToString();
but time also showing in text box..how to get date only in text box

解决方案

Use the date format of your choice in the ToString

Txtdateofbirth=sdr.GetValue(2).ToString("dd/MM/yyyy");



Might need to cast it first though

Txtdateofbirth=((DateTime)sdr.GetValue(2)).ToString("dd/MM/yyyy");



This assumes the field is stored as a Date or DateTime field, if it isn't then it should be.


SqlDataAdapter sda=cmd.ExecuteReader();
While(sda.Read())
{
DateTime dt=Convert.ToDateTime(sda["DateOfBirth"]);
}


这篇关于如何从数据库中检索日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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