|
-
Jan 19th, 2013, 04:33 PM
#1
Thread Starter
New Member
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
-
Jan 19th, 2013, 08:12 PM
#2
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.
-
Jan 20th, 2013, 05:20 AM
#3
Thread Starter
New Member
Re: Importing from file to database
 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!
-
Jan 20th, 2013, 08:54 AM
#4
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.
-
Jan 31st, 2013, 04:42 PM
#5
Thread Starter
New Member
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:
|
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
-
Feb 2nd, 2013, 01:22 AM
#6
Registered User
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|