Importing from file to database
Hi,
I am quite new to this forum and I have a question regarding data import from a simple text file to a database.
I am trying to write a code that takes the text from the attached file and import it to my database. Can anybody help my?
I would prefer if it could be imported in to one row in the database in stead of being spread out over multiple.
Attachment 95425
Kind regards,
Lasse Jepsen
Re: Importing from file to database
You can call File.ReadAllText to get the entire contents of a file as a String and then saving it to a database is the same as for any other String. If you don't know how to save a String to a database then you should follow the Database FAQ link in my signature and check out the .NET resources there to learn how to use ADO.NET.
Re: Importing from file to database
Quote:
Originally Posted by
jmcilhinney
You can call File.ReadAllText to get the entire contents of a file as a String and then saving it to a database is the same as for any other String. If you don't know how to save a String to a database then you should follow the Database FAQ link in my signature and check out the .NET resources there to learn how to use ADO.NET.
Thank you for the reply. I will give it a go!
Re: Importing from file to database
The duplicate of this thread has been deleted.
When posting new threads please follow our one topic, one thread, in one forum section philosophy. Multiple threads on the same topic will either be merged into one (if both have replies) or deleted outright.
Re: Importing from file to database
Once again thank you for the reply. I have managed to convert my txt file to at string. If I try to import this string as a flat file with the SQL Server import software I can do so. I have tried to read through your tutorials, however, I am unable to suceed in importing the string to my database. Here is how my code looks like:
Code:
Dim connectionString As String =
"Data Source=BÆRBAR\SQLEXPRESS;" &
"Initial Catalog=TEST;" &
"Integrated Security=True;Pooling=False"
Dim linkToDB As New SqlConnection(
connectionString)
linkToDB.Open()
Dim commandWrapper As New SqlCommand(
"BULK INSERT [import contact] FROM " & fileReader &
" WITH ( FIELDTERMINATOR = ';' , ROWTERMINATOR = '|' ) ", linkToDB)
MsgBox(fileReader)
My string looks like this:
Quote:
|
9999;
1347089590;
0;
906000;
B;
;
false;
0;
0;
0;
0;
;
Hejsa;
2;
Non-MILCO;
false;
No info;
0;
0;
0;
;
Not Dealt With;
0.975164456623246;
0.196728754225765;
2;
Non-MILCO;
1.1;
Can anybody help me to get this corrected?
Kind regards
Re: Importing from file to database
i think you need to call file.ReadAllText to get the entire contents of a file as String and then saved it to a DB.