日期:2014-05-18  浏览次数:20410 次

还是时间转换问题
string id = ListBox2.Items[i].Value.ToString(); 
  int cid = Convert.ToInt32(id); 
  string tc = this.DropDownList1.SelectedValue.ToString(); 
  int tc_id = Convert.ToInt32(tc); 
  string title = this.TextBox1.Text.Trim(); 
  string content = this.TextBox2.Text; 
  string date =Convert .ToString( this.CalendarUC1.SelectedDate); 
  string hours = this.DropDownList2.SelectedValue.ToString(); 
  string second = this.DropDownList3.SelectedValue.ToString(); //string the_date = string.Format("{0} {1}:{2}", date, hours, second);//2008-10-25 0:00:00 
  string the_date = date + " " + hours + ":" + second +":"+"00"; 
  DateTime tdate =DateTime.Parse( the_date); 
  tr.add_train(cid, title, content, tc_id, tdate); 
  DataSet ds = tr.find_t_id(cid, title); 
  tra[i] = ds.Tables[0].Rows[0]["T_id"].ToString(); 
  int ti = Convert.ToInt32(tra[i]); 
  tr.add_train_id(ti); 
  ds.Dispose(); 
该字符串未被识别为有效的 DateTime。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.FormatException: 该字符串未被识别为有效的 DateTime。 

源错误: 


行 105: //string the_date = string.Format("{0} {1}:{2}", date, hours, second);//2008-10-25 0:00:00 
行 106: string the_date = date + " " + hours + ":" + second +":"+"00"; 
行 107: DateTime tdate =DateTime.Parse( the_date);行 108: tr.add_train(cid, title, content, tc_id, tdate); 
行 109: DataSet ds = tr.find_t_id(cid, title); 


------解决方案--------------------
字符串格式不正确,所以被PARSE的时候才出现问题的。

可以接受的格式标准情况下为:2008-8-12 1:2:3
这样的,你转换一下应该就可以了。