0
System.InvalidOperationException:集合已被修改;可能無法執行枚舉操作
private void btnGetUpdatedSchema_Click(object sender, EventArgs e)
{
lviewMainDbSchema.Items.Clear();
string conString = null;
conString = "Data source=" + txtUpdatedServerName.Text + ";Password=" + txtUpdatedPassword.Text + ";Initial Catalog=" + txtUpdatedDatabaseName.Text + ";User ID=" + txtUpdatedUserId.Text + ";";
con = new SqlConnection(conString);
try
{
int tblTotal = 0;
GetTables(conString, tblMainList, tblTotal);
foreach (var list in tblMainList)
{
con.Open();
string query = "SELECT * FROM" + " " + list;
cmd = new SqlCommand(query, con);
dr = cmd.ExecuteReader();
dt = dr.GetSchemaTable();
con.Close();
foreach (DataRow dt_row in dt.Rows)
{
foreach (DataColumn dt_col in dt.Columns)
{
lviewMainDbSchema.Items.Add(string.Format("{0}={1}", dt_col.ColumnName, dt_row[dt_col]).ToString());
//HERE WHERE I GOT THE ERROR!! :) :) :) <3
tblMainList.Add(string.Format("{0}={1}", dt_col.ColumnName, dt_row[dt_col]).ToString());
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("ERROR!!!!" + ex);
}
}
- 列表項
謝謝工程:) –