问题描述
大家好,
我尝试了很多链接,但我无法找到解决方案。请求您对以下查询的专业知识:
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
推荐答案
str = "select partyname from casetab WHERE jdate='" +Convert.ToDateTime(listJDate.SelectedItem.ToString()).Year.ToString() + "'";
希望这有助于
Hope this helps
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
}
这篇关于将字符串转换为列表框中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!