private void toolStripLabel2_Click(object sender, EventArgs e) { try { DataTable dt = dataGridView1.DataSource as DataTable; if (dt == null) { dt = new DataTable(); //dt.Columns.Add("Id", typeof(int)); for (int i = 0; i < dataGridView1.Columns.Count; i++) { //if (!dataGridView1.Columns[i].HeaderCell.Value.ToString().Equals("Id")) //{ dt.Columns.Add(dataGridView1.Columns[i].HeaderCell.Value.ToString(), typeof(String)); //} } for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells[6].Value != null) { dt.Rows.Add(dataGridView1.Rows[i].Cells[0].Value, dataGridView1.Rows[i].Cells[1].Value, dataGridView1.Rows[i].Cells[2].Value, dataGridView1.Rows[i].Cells[3].Value, dataGridView1.Rows[i].Cells[4].Value, dataGridView1.Rows[i].Cells[5].Value, dataGridView1.Rows[i].Cells[6].Value, dataGridView1.Rows[i].Cells[7].Value, dataGridView1.Rows[i].Cells[8].Value, dataGridView1.Rows[i].Cells[9].Value, dataGridView1.Rows[i].Cells[10].Value, dataGridView1.Rows[i].Cells[11].Value, dataGridView1.Rows[i].Cells[12].Value, dataGridView1.Rows[i].Cells[13].Value, dataGridView1.Rows[i].Cells[14].Value, dataGridView1.Rows[i].Cells[15].Value, dataGridView1.Rows[i].Cells[16].Value, dataGridView1.Rows[i].Cells[17].Value, dataGridView1.Rows[i].Cells[18].Value, dataGridView1.Rows[i].Cells[19].Value, dataGridView1.Rows[i].Cells[20].Value, dataGridView1.Rows[i].Cells[21].Value); } } } this.backgroundWorker1.RunWorkerAsync(); // 运行 backgroundWorker 组件 JingDu form = new JingDu(this.backgroundWorker1, "提交中"); // 显示进度条窗体 form.ShowDialog(this); form.Close(); cal.insertPeise(dt, cb_MianLiao.Text, dateTimePicker1.Text); MessageBox.Show("提交成功!"); string cbtext = cb_MianLiao.Text; PeiSeBiaoLuru_Load(sender, e); cb_MianLiao.Text = cbtext; } catch (Exception ex) { //throw ex; MessageBox.Show(ex.Message); } }