private void AttendenceDataView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (AttendenceDataView.Columns[e.ColumnIndex].Name == "Update")
            {
                DBAccess.GetInstance().UpdateAttendence(int.Parse(AttendenceDataView["迟到次数", e.RowIndex].ToString()), int.Parse(AttendenceDataView["早退次数", e.RowIndex].ToString()),
                                                         int.Parse(AttendenceDataView["旷课次数", e.RowIndex].ToString()), int.Parse(AttendenceDataView["请假次数", e.RowIndex].ToString()),
                                                         AttendenceDataView["事因", e.RowIndex].ToString(), AttendenceDataView["备注", e.RowIndex].ToString(), cbYear.Text, AttendenceDataView["学号", e.RowIndex].ToString());            }
        }
我在数据库中迟到,早退,旷课,请假都是int类型,而在在datagridview中读出数据时用了int.parse()转换,不知道那里出错了,报错说:输入字符串的格式不正确。
高手们帮帮小弟!拜谢!

解决方案 »

  1.   

    int转换对应的字段有字符串或者为空,就是存在不能转换为int的数据,调试一下看看
      

  2.   

    在 if (AttendenceDataView.Columns[e.ColumnIndex].Name == "Update")
    这里打断点,调试下,看看是不是生成的sql里边多了什么东西。
      

  3.   

    在这里打断点。DBAccess.GetInstance().UpdateAttendence
      

  4.   

    数据格式的原因,你的数据取出来时object类型的,你用
    Convert.ToInt32()
    int.Parse 只能转换数字类型的字符串(string),
    而Convert.ToInt32 可以转换的类型较多。
      

  5.   

    吁~~~~~
    刚看到楼主代码后边的ToString()。