错误:方法 "ToString" 没有重载,需要 1 个参数



我想将所有DataGridView行插入数据库。我面临这个错误

方法"没有过载;ToString";接受1个参数。

for (int i = 0; i < TimesDgv.Rows.Count - 1; i++)
{
OleDbCommand cmd = new OleDbCommand("Insert into TimesTBL(PeriodName,TimeFrom,TimeTo,Duration) values (@PeriodName,@TimeFrom,@TimeTo,@Duration)", con);
cmd.Parameters.AddWithValue("PeriodName", TimesDgv.Rows[i].Cells[0].Value);
cmd.Parameters.AddWithValue("TimeFrom", TimesDgv.Rows[i].Cells[1].Value.ToString("hh:mm"));
cmd.Parameters.AddWithValue("TimeTo", TimesDgv.Rows[i].Cells[2].Value.ToString("hh:mm"));
cmd.Parameters.AddWithValue("Duration", TimesDgv.Rows[i].Cells[3].Value);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
cmd = null;
}

在此处输入图像描述

您似乎认为TimesDgv.Rows[i].Cells[1].ValueDateTimeTimeSpan。但事实并非如此。就编译器而言不是这样。

也许你想把它解析或铸造成一个?

最新更新