错误是:索引超出范围。必须是非负数且小于集合的大小。
场景:我有一个桌面应用程序,它加载 XML 文件并在网格中显示数据。现在,我想插入另一个文件并想在两个文件中追加数据。但是,当我尝试合并数据时(我的意思是将行添加到具有先前打开的文件行的 DataTable)...我收到此错误。
if (strPreviousFile != "")
{
dgvBooksDetails.DataSource = dtBooks;
int intCurrentRows = dgvBooksDetails.Rows.Count;
intBooksCounter = intBooksCounter + intCurrentRows;
for (int c = intCurrentRows; c < intBooksCounter; c++)
{
Book objBook = new Book();
objBook.ID = BookID[c];
objBook.Title = BookTitle[c];
objBook.Author = BookAuthor[c];
objBook.Genre = BookGenre[c];
objBook.Price = Double.Parse(BookPrice[c]);
objBook.PublishDate = DateTime.Parse(BookPublish_Date[c]);
objBook.Description = BookDescription[c];
dtBooks.Rows.Add(objBook.ID, objBook.Title, objBook.Author, objBook.Genre,
objBook.Price, objBook.PublishDate, objBook.Description);
}
}
我该如何克服这个错误?