说明dataGridView1.Rows[j].Cells[k].Value为null了你修改为:tempStr += Convert.ToString(dataGridView1.Rows[j].Cells[k].Value);