我想把GridView里某一列的float的属性值 和 我从别的函数getrecord取出来的另外的一个float值比较大小 私以为if条件里的判断条件没有语法

yangrunxin 2016-12-26 06:37:23
我想把GridView里某一列的float的属性值 和 我从别的函数getrecord取出来的另外的一个float值比较大小
私以为if条件里的判断条件没有语法问题
但是当我在datagridview里插入float值,比如7.0时,出现
未处理的“System.FormatException”类型的异常出现在 mscorlib.dll 中。
其他信息: 输入字符串的格式不正确。
这个问题,求解答!




if (Convert.ToSingle(this.dataGridView1.Rows[i].Cells[4].Value.ToString())< record.getrecord("" + this.dataGridView1.Rows[i].Cells[3].Value + ""))


SqlConnection conn = new SqlConnection(Properties.Settings.Default.sportsmeetingConnectionString1);
SqlCommand cmd1 = new SqlCommand();
SqlCommand cmd2 = new SqlCommand();
SqlCommand cmd3 = new SqlCommand();
cmd1.CommandText = "update item set athid='" + this.dataGridView1.Rows[i].Cells[0].Value + "' where itemname = '" + this.dataGridView1.Rows[i].Cells[3].Value + "'";
cmd2.CommandText = "update item set athname='" + this.dataGridView1.Rows[i].Cells[1].Value + "' where itemname = '" + this.dataGridView1.Rows[i].Cells[3].Value + "'";
cmd3.CommandText = "update item set record='" + this.dataGridView1.Rows[i].Cells[4].Value + "' where itemname = '" + this.dataGridView1.Rows[i].Cells[3].Value + "'";
cmd1.Connection = conn;
cmd2.Connection = conn;
cmd3.Connection = conn;
try
{
conn.Open();
int num = cmd1.ExecuteNonQuery();
int num1 = cmd2.ExecuteNonQuery();
int num2 = cmd3.ExecuteNonQuery();

}
catch (Exception err)
{ MessageBox.Show(err.Message); }
finally
{ conn.Close(); }
}
...全文
77 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
你老师看到这代码会气死吧
  • 打赏
  • 举报
回复
年底了,技术区来了一大波找答案的学生
巴士上的邂逅 2016-12-27
  • 打赏
  • 举报
回复
那还是因为Cells[4].Value或者Cells[3].Value有问题不能转换为float类,将Cells[4].Value或者Cells[3].Value赋值给一个变量调试一下看看是什么值

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧