简体   繁体   English

错误:方法“ToString”没有重载需要 1 arguments

[英]Error : No overload for method "ToString" takes 1 arguments

I want to insert all DataGridView rows to Database.我想将所有 DataGridView 行插入数据库。 I faced this error我遇到了这个错误

No overload for method "ToString" takes 1 arguments.方法“ToString”没有重载需要 1 个 arguments。

 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;
  }

enter image description here在此处输入图像描述

You seem to think that TimesDgv.Rows[i].Cells[1].Value is a DateTime or TimeSpan .您似乎认为TimesDgv.Rows[i].Cells[1].ValueDateTimeTimeSpan But it's not.但事实并非如此。 Not as far as your compiler is concerned.就您的编译器而言,并非如此。

Maybe you meant to Parse or Cast it into one?也许您打算解析或将其转换为一个?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM