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
Farhan Shariff
NA
933
241.6k
Delete empty cells in CSV files
May 8 2014 5:53 AM
I am importing .csv files into datatables
I want to display Message whenever there is empty values detected in the cell and also delete them and then continue the program
private static DataTable GetDataTabletFromCSVFile1(string csv_file_path1)
{
DataTable table2 = new DataTable("Real");
try
{
using (TextFieldParser csvReader1 = new TextFieldParser(csv_file_path1))
{
csvReader1.SetDelimiters(new string[] { "," });
csvReader1.HasFieldsEnclosedInQuotes = true;
string[] colFields = csvReader1.ReadFields();
foreach (string column in colFields)
{
DataColumn datecolumn2 = new DataColumn(column);
datecolumn2.AllowDBNull = true;
table2.Columns.Add(datecolumn2);
}
while (!csvReader1.EndOfData)
{
string[] fieldData1 = csvReader1.ReadFields();
//Making empty value as null
for (int i = 0; i < fieldData1.Length; i++)
{
if (fieldData1[i] == "")
{
fieldData1[i] = null;
}
}
table2.Rows.Add(fieldData1);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Select New File");
}
return table2;
}
Reply
Answers (
17
)
doubt in saving Records in database
Assignment C#