在C#中转换DateTime时出现异常

时间:2016-01-18 07:06:28

标签: c#

我确实需要将DateTime列分为Date和Time列。因此,当我试图转换DateTime时,它会给我错误说明

  

" ArgumentOutofRangeException未处理"

在线

dataGridView1.Rows[i].Cells[txtColumnName.Text.Replace(" ", "")].Value = Time.ToString("HH:mm:ss");.

以下是我完成的代码:

private void btnSplit_Click(object sender, EventArgs e)
{
    DataGridViewTextBoxColumn dgvcdate = new DataGridViewTextBoxColumn();
    dgvcdate.Name = cmbColumnCombo.Text;
    dgvcdate.HeaderText = cmbColumnCombo.Text;
    dataGridView1.Columns.Add(dgvcdate);

    DataGridViewTextBoxColumn dgvctime = new DataGridViewTextBoxColumn();
    dgvctime.Name = txtColumnName.Text.Replace(" ", "");
    dgvctime.HeaderText = txtColumnName.Text;
    dataGridView1.Columns.Add(dgvctime);

    for (int RowCount = 1; RowCount <= strfile.Length - 1; RowCount++)
    {
        if (strfile[RowCount].ToString() != "")
        {
            if (RowCount != 0)
            {
                string[] column = strfile[RowCount].Split('þ');
                for (int i = 1; i < column.Length - 1; i++)
                {
                    if ((cmbColumnCombo.SelectedIndex == ((i - 1) / 2)))
                    {
                        dataGridView1.Rows.Add();

                        if (column[i].ToString() != "\u0014")
                        {
                            DateTime Time = Convert.ToDateTime(column[i]);
                   //         DateTime Time = (DateTime)column[i]; 
                     dataGridView1.Rows[i].Cells[txtColumnName.Text.Replace(" ", "")].Value = Time.ToString("HH:mm:ss");
                         dataGridView1.Rows[i].Cells[cmbColumnCombo.Text].Value = Time.ToString("dd/MM/yyyy");
                            //dataGridView1.Rows[RowCount - 1].Cells[cmbColumn1.Text].Value += column[i].ToString();
                        }
                    }
                }
            }
        }

0 个答案:

没有答案