我的代码有什么问题??
string birthdate = ((DataRowView)comboBox1.SelectedItem).Row["birthdate"].ToString(); //pulled the data into the database ()
string[] split = birthdate.Split('/'); //split the Date我想把它们放在一个文本框中,所以我想这样做:
textbox1.Text = split[0]; //correct, gets the 1st word the (Day)
textbox2.Text = split[1]; //incorrect, outofrange exception (Month)
textbox3.Text = split[2]; //incorrect, outforange exception (Year)注:格式为日/月(字)/Year ==> 1/1月/2012
有人能帮我获取这些值并将它们逐个放入文本框中吗?
发布于 2012-01-22 00:32:58
这个问题实际上是从在varchar类型的列中存储日期开始的。只需要一台区域性设置错误的机器就会损坏数据库表,因此所有试图读取它的机器都会崩溃。解决真正的问题,修好桌子。
不管怎样,你会想要改进你的代码,这样dbase管理员就有机会修复损坏的东西。抛出一个能提供足够信息的异常。类似于:
string[] split = birthdate.Split('/');
if (split.Length != 3) {
throw new Exception("Invalid date string for table entry " + row["primarykey"].ToString());
}https://stackoverflow.com/questions/8954219
复制相似问题