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
save csv file in database
Aug 20 2020 8:45 PM
Hello and hi, why this got does not execute if condition ? it goes straight to else even though the file name already in database. I need to do if the csv file name already save in database, it will print out file exist. please help me
foreach
(FileInfo file
in
filess) {
DateTime lastWriteTime = file.LastWriteTime;
Console.WriteLine(
"File list : "
+ file);
Console.WriteLine(
"Time last Edit : "
+ lastWriteTime);
if
(File.Exists(
"file"
)) {
Console.WriteLine(
"File Name Exist!"
);
var sel =
"select * from listfile where filename = @filename"
;
var cmd2 =
new
NpgsqlCommand(sel, conn);
conn.Open();
cmd2.Parameters.AddWithValue(
"@filename"
, file);
Console.WriteLine(file +
" exist in database."
);
cmd2.ExecuteNonQuery();
conn.Close();
}
else
{
Console.WriteLine(
"File Name NOT Exist!"
);
var lf =
"insert into listfile(filename)values(@filename)"
;
var cmd =
new
NpgsqlCommand(lf, conn);
conn.Open();
cmd.Parameters.AddWithValue(
"filename"
, Convert.ToString(file));
string
filename1 = cmd.Parameters[
"@filename"
].Value.ToString();
Console.WriteLine(
"Record inserted successfully. filename = "
+ file);
cmd.ExecuteNonQuery();
conn.Close();
}
}
Reply
Answers (
4
)
How to Enter Urdu Characters in DatagridView Cell in C#
Time calculation