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
Hasibul Kamel
NA
44
4.2k
compare csv records in database and add new line
Sep 3 2020 11:44 AM
Hi, wanna ask, how to compare CSV from CSV file and database? I using lastwritetime to see changes in CSV. If lastwritetime same, it means there are no new records in the CSV file. If lastwritetime got changes, it means there are new records added in CSV file and I want to add it to database without duplicate the records. Means only insert the new records into database. Help me please.
var lwt =
"select COUNT(*) from listfile where lastwritetime=@lastwritetime"
;
var cmd2 =
new
NpgsqlCommand(lwt, conn);
cmd2.Parameters.AddWithValue(
"lastwritetime"
, Convert.ToDateTime(lastWriteTime));
int
LWT = Convert.ToInt32(cmd.ExecuteScalar());
cmd2.ExecuteNonQuery();
if
(LWT > 0)
{
Console.WriteLine(
"There are no changes in lastWriteTime CSV file"
);
}
else
{
Console.WriteLine(
"There are changes lastWriteTime in CSV file"
);
var lf2 =
"insert into listfile(filename,lastwritetime)values(@filename,@lastwritetime)"
;
var cmd3 =
new
NpgsqlCommand(lf2, conn);
cmd3.Parameters.AddWithValue(
"filename"
, Convert.ToString(file));
string
filename = cmd3.Parameters[
"@filename"
].Value.ToString();
Console.WriteLine(
"Record inserted successfully. filename = "
+ file);
cmd3.Parameters.AddWithValue(
"lastWriteTime"
, Convert.ToDateTime(lastWriteTime));
string
time = cmd3.Parameters[
"@lastwritetime"
].Value.ToString();
Console.WriteLine(
"Record inserted successfully. lastWriteTime = "
+ lastWriteTime);
cmd3.ExecuteNonQuery();
}
Reply
Answers (
3
)
Web API : always showing message content type must be application/json
How to respond in header with 401 API C # code