private void Func()
{
{
_dt = null;
}
_dt = new DataTable();
DataRow dr = null;
_dt.Columns.Add("商品", typeof(string));
_dt.Columns.Add("售价", typeof(double));
_dt.Columns[0].Caption = "System.String";
_dt.Columns[0].DataType = typeof(string);
_dt.Columns[1].Caption = "System.Double";
_dt.Columns[1].DataType = typeof(double);
for (int i = 0; i < dataGridView1.RowCount - 1; i++)
{
if (dr == null)
{
dr = _dt.NewRow();
}
for (int j = 0; j < dataGridView1.ColumnCount; j++)
{
dr[j] = dataGridView1.Rows[i].Cells[j].Value;
}
_dt.Rows.Add(dr);
dr = null;
}
}
{
DataTable _dt=null;
if (_dt != null){
_dt = null;
}
_dt = new DataTable();
DataRow dr = null;
_dt.Columns.Add("商品", typeof(string));
_dt.Columns.Add("售价", typeof(double));
_dt.Columns[0].Caption = "System.String";
_dt.Columns[0].DataType = typeof(string);
_dt.Columns[1].Caption = "System.Double";
_dt.Columns[1].DataType = typeof(double);
for (int i = 0; i < dataGridView1.RowCount - 1; i++)
{
if (dr == null)
{
dr = _dt.NewRow();
}
for (int j = 0; j < dataGridView1.ColumnCount; j++)
{
dr[j] = dataGridView1.Rows[i].Cells[j].Value;
}
_dt.Rows.Add(dr);
dr = null;
}
}