//保存考勤,通过将dataGrideview中的每行转换为实体对象属性,在调用dao中的相应方法 private void button1_Click(object sender, EventArgs e) { lilunCount = rows;; for (int i = 0; i < rows; i++) { string stu_id = dataGridView1.Rows[i].Cells[3].Value.ToString().Trim(); string stu_name = dataGridView1.Rows[i].Cells[2].Value.ToString().Trim(); string cur_state = dataGridView1.Rows[i].Cells[4].Value.ToString().Trim(); Check ck = new Check(); ck.Stu_Id = stu_id; ck.Stu_Name = stu_name; ck.State = cur_state; ck.Ck_Time = ck_time; ck.Cou_Id = cou_id; ck.Tea_Id = tea_id; sijiCount += teaDao.SaveData(ck); } if (sijiCount == lilunCount) { MessageBox.Show("保存成功"); button1.Enabled = false; } else { MessageBox.Show("保存失败"); } /* //将datagrideview转换为datatable * CommonDgvToTable Dgvtotable = new CommonDgvToTable(); * DataTable dt = Dgvtotable.GetDgvToTable(dataGridView1); * //将DataTable 转换为实体 * CommonLeiconvertTable<CKStudenkModel> ConTable = new CommonLeiconvertTable<CKStudenkModel>(); * List<CKStudenkModel> list = ConTable.ConvertToList(dt); * sijiCount = teaDao.SaveData(list); * if (sijiCount == lilunCount) * { * MessageBox.Show("保存成功"); * button1.Enabled = false; * } * else * { * MessageBox.Show("保存失败"); * } */ }