//批量导入身高 private void BatchInputHeight_Click(object sender, RoutedEventArgs e) { string acitivityId = Uid; CheckDataUtill checkDataUtill = new CheckDataUtill(); OpenFileDialog ofd = new OpenFileDialog { Title = "请选择批量导入文件", Filter = "excel文件(*.xlsx)|*.xlsx|所有文件(*.*)|*.*" }; if (ofd.ShowDialog() == DialogResult.OK) { string path = Path.GetFullPath(ofd.FileName); DataTable dt = checkDataUtill.DBExcelToDataTable(path, "Sheet1"); int errcount = 0; try { for (int i = 0; i < dt.Rows.Count; i++) { string studentId = dt.Rows[i][0].ToString(); string height = dt.Rows[i][2].ToString(); double height_int = double.Parse(height); int count = dbUtill.UpdateStudentHeight(studentId, height_int); if (count < 1) { System.Windows.MessageBox.Show("导入失败,不存在学号为" + studentId + "的学生", "错误"); errcount = ++errcount; } } if (errcount == 0) { System.Windows.MessageBox.Show("全部导入成功", "成功"); } else { System.Windows.MessageBox.Show("导入失败" + errcount.ToString() + "条", "错误"); } } catch (Exception ex) { System.Windows.MessageBox.Show("批量导入失败,因为" + ex.Message, "错误"); } } }