TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Daniel Koh
NA
60
15.5k
csv to datatable sudden error
Nov 8 2017 9:01 PM
string
CSVFilePathName = @
"C:\test.csv"
;
string
[] Lines = File.ReadAllLines(CSVFilePathName);
string
[] Fields;
Fields = Lines[0].Split(
new
char
[] {
','
});
int
Cols = Fields.GetLength(0);
DataTable dt =
new
DataTable();
//1st row must be column names; force lower case to ensure matching later on.
for
(
int
i = 0; i < Cols; i++)
dt.Columns.Add(Fields[i].ToLower(),
typeof
(
string
));
DataRow Row;
for
(
int
i = 1; i < Lines.GetLength(0); i++)
{
Fields = Lines[i].Split(
new
char
[] {
','
});
Row = dt.NewRow();
for
(
int
f = 0; f < Cols; f++)
Row[f] = Fields[f];
dt.Rows.Add(Row);
}
This is the code I have, which was working fine yesterday. However today without any changes made to the code it says:
System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'
Any possible solutions?
Reply
Answers (
2
)
Generate digital signature in PDF and verify the certificate
Tablelayout panel control