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
Abdalla Omran
NA
334
32k
How could I check if import this text file into DB or not ?
Jan 8 2020 3:52 AM
Hello everyone .
I have wrote a code which is reading Text Files and save them in a list after that import this list into DB so far it's fine the problem is i have until now 400 text fiels each text fiel has around 300000 until 500000 line and each time want to import a new text flel it will reinsert or reimport the text files which are already imported . that's meaing my data will be always duplicated.
so how could i check with C# code if this text files is already imported or exist in DB ?!
here is some code to be more clear :
private
static
List<WebShopDataAccess> GetWebShopDataAccesses(
string
path)
{
List<WebShopDataAccess> elements =
new
List<WebShopDataAccess();
List<
string
> lines = File.ReadAllLines(path).ToList();
return
elements;
// here i am gettng the list back then import this list into DB during an extensions method with sqlbulk
}
private
static
void
ImportToDB()
{
string
CS =
""
using
(SqlConnection connection =
new
SqlConnection(CS))
{
SqlBulkCopy bulkCopy =
new
SqlBulkCopy(connection, SqlBulkCopyOptions.TableLock | SqlBulkCopyOptions.FireTriggers | SqlBulkCopyOptions.UseInternalTransaction,
null
);
bulkCopy.DestinationTableName =
"TestWebShop"
;
connection.Open();
bulkCopy.WriteToServer(GetListOfWebShop.AsDataTable());
}
}
Reply
Answers (
3
)
How to refer two classes inside a single class in C#?
I need to find the largest number from a file and display it