【发布时间】:2019-10-16 07:27:21
【问题描述】:
我正在为一个新项目工作,我的问题是 2 个月前我停止了编程工作,所以我又遇到了这个问题。
private void LoadData()
{
con.dataGet("Select * from [User]");
DataTable dt = new DataTable();
con.sda.Fill(dt);
foreach(DataRow row in dt.Rows)
{
int n = dataGridView1.Rows.Add(); //Errors here
dataGridView1.Rows[n].Cells["dgSno"].Value = n +1; //Not part of my database
dataGridView1.Rows[n].Cells["dgName"].Value = row["Name"].ToString();
dataGridView1.Rows[n].Cells["dgDob"].Value = Convert.ToDateTime(row["Dob"].ToString()).ToString("ddd/mm/yy");
dataGridView1.Rows[n].Cells["dgEmail"].Value = row["Email"].ToString();
dataGridView1.Rows[n].Cells["dgUserName"].Value = row["UserName"].ToString();
dataGridView1.Rows[n].Cells["dgRole"].Value = row["Role"].ToString();
dataGridView1.Rows[n].Cells["dgAddress"].Value = row["Address"].ToString();
}
}
错误:An unhandled exception of type 'System.InvalidOperationException' occured in System.Windows.Forms.dll
【问题讨论】:
-
dateGridView1.Rows.Add(row);
-
我有一个列名不属于数据库 sql server 上的单元格是 dgSno
标签: c# sql-server row