SqlDataReader用于数据类型Time [英] SqlDataReader for data type Time
本文介绍了SqlDataReader用于数据类型Time的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我正在尝试读取数据类型TIME但它会抛出此异常:
无法将System.TimeSpan类型的对象强制转换为类型System.String。
这是我的代码:
Hello guys I'm trying to read data type TIME but it throws this exeption:
Unable to cast object of type System.TimeSpan to type System.String.
Here is my code:
SqlCommand novyprikaz = new SqlCommand("SELECT * FROM stanice WHERE id=" + selectrow, spojeni);
spojeni.Open();
SqlDataReader precti = novyprikaz.ExecuteReader();
if (precti.Read())
{
textBox2.Text = precti.GetString(precti.GetOrdinal("odjezd"));
}
如何改进我的代码以读取此数据类型TIME?
列odjezd在数据类型TIME
在此先感谢
How should I improve my code to read it this data type TIME ?
column "odjezd" is in data type TIME
Thanks in advance
推荐答案
string time = Convert.ToDateTime(row["PO_Date"].ToString()).ToString("dd-MMM-yyyy");
尝试:
Try:
string time = new DateTime(precti.GetOrdinal("odjezd").Ticks).ToString("HH:mm:ss");
看看是否有效。
See if this works.
这篇关于SqlDataReader用于数据类型Time的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文