/// <summary>
        /// datagridview to a datatable
        /// geovindu 涂聚文
        /// </summary>
        /// <param name="dataGridView"></param>
        /// <returns></returns>
        private DataSet DataGridViewToDatSet(DataGridView dataGridView)
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            dt.TableName = "StaffStateList";
            foreach (DataGridViewColumn col in dataGridView.Columns)
            {
                dt.Columns.Add(col.DataPropertyName, col.ValueType);
            }
            foreach (DataGridViewRow gridRow in dataGridView.Rows)
            {
                if (gridRow.IsNewRow)
                    continue;

                DataRow dtRow = dt.NewRow();
                for (int i1 = 0; i1 < dataGridView.Columns.Count-1; i1++)
                    dtRow[i1] = (gridRow.Cells[i1].Value == null ? DBNull.Value : gridRow.Cells[i1].Value);
                dt.Rows.Add(dtRow);
            }
            ds.Tables.Add(dt);
            //System.Diagnostics.Debugger.Break();
            return ds;

        }

相关文章:

  • 2022-12-23
  • 2022-03-01
  • 2021-08-30
  • 2021-11-24
  • 2021-09-19
  • 2022-12-23
  • 2021-07-25
猜你喜欢
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2022-03-06
  • 2021-12-11
  • 2021-07-29
  • 2022-12-23
相关资源
相似解决方案