DataTable dt1 = new DataTable();
dt1.Columns.Add("studid",typeof(int));
dt1.Columns.Add("rollno", typeof(int));
dt1.Columns.Add("date", typeof(DateTime));
dt1.Columns.Add("starttime", typeof(string));
dt1.Columns.Add("class", typeof(string));
dt1.Columns.Add("section", typeof(string));
dt1.Columns.Add("subject", typeof(string));
for (int i = 0; i < dt.Rows.Count; i++)
{
dt1.Rows.Add(Convert.ToInt32(dt.Rows[i]["id"]), Convert.ToInt32(dt.Rows[i]["rollno"]), Convert.ToDateTime(txtdate.Text),time.SelectedItem.ToString(), drpclass.SelectedItem.ToString(), drpsection.ToString(), drpsubject.SelectedItem.ToString());
}
即使 DataTable 列的数据类型是字符串,"String was not recognized as a valid DateTime"
我也会收到错误消息。time.SelectedItem.ToString()
我应用了断点,09:30:00
这是我得到的值time.SelectedItem.ToString()