将字符串转换为列表框中的日期 [英] Convert String into Date in a listbox

查看:73
本文介绍了将字符串转换为列表框中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我尝试了很多链接,但我无法找到解决方案。请求您对以下查询的专业知识:



1.我有一个列表框,其中填充了数据库中的日期。我只想在列表框中显示年份。请指教。



2.这是当前的select语句:str =select caseyname from casetab WHERE jdate =''+ listJDate.SelectedItem.ToString()+ '';



如何在select语句中将字符串转换为日期时间,以便我可以在列表框中添加selectIndexChanged事件。





请指教。



-

NG

Hi All,

I tried many links but I am unable to find a solution. Request your expertise for the below queries:

1. I have a listbox where dates from the database are populated. I want only year to be displayed in the listbox. Please advise.

2. This is the current select statement : str = "select partyname from casetab WHERE jdate=''" +listJDate.SelectedItem.ToString() + "''";

How do I convert string to datetime in select statement so I can add in the listbox selectIndexChanged event.


Please advise.

--
NG

推荐答案

试试这个

Try this
str = "select partyname from casetab WHERE jdate='" +Convert.ToDateTime(listJDate.SelectedItem.ToString()).Year.ToString() + "'";



希望这有助于


Hope this helps


关于第2项。

您可以使用DateTime类的Parse功能:

Regarding item 2.
You can use the Parse functionality of the DateTime class:
string datetime_as_string = "<Your date time string here>";
DateTime datetime;
try {
    datetime = DateTime.Parse(datetime_as_string);
}
catch(FormatException fEx) {
    // handle the failure here, the string was not in a valid format
}


这篇关于将字符串转换为列表框中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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