Avatar billede thomas_regin Nybegynder
04. april 2002 - 11:35 Der er 11 kommentarer og
1 løsning

Csv til DB!

Hejsa!

Jeg har et problem med en semikolon-separeret teksfil!..

Den ser således ud:

bannerreklame24.mpg;18:56 02/03/2002;
bannerreklame22.mpg;19:20 02/03/2002;
bannerreklame16.mpg;12:56 02/03/2002;
bannerreklame70.mpg;13:20 02/03/2002;

Mit problem opstår, når jeg skal have indholdet ud i nogle variabler, som jeg kan smide i databasen!

Set tf = FSO.OpenTextFile("C:\2450.txt")
Do While Not tf.AtEndOfStream
    theContent = theContent & tf.ReadLine
Loop
tf.Close
theContent2 = Left(theContent, Len(theContent) - 1)
splitItUp = Split(theContent2, ";")
    For Each x In splitItUp
      'Her opstår mit problem!
    Next

Som sagt, så skal jeg bruge en funktion, der smider de respektive værdier ud i nogle variabler, som jeg så senere kan smide op i databasen!.. Hver linie i tekstfilen skal være et nyt insert statement i SQL-serveren hvori jeg har to values: Første separerede værdi og anden separerede værdi!

Håber at i kan være behjælpelige!

På forhånd tak,

Thomas Regin.
Avatar billede terry Ekspert
04. april 2002 - 11:38 #1
Hi Thomas>
Are you talking about MS SQL Server?
If your file looks like this
bannerreklame24.mpg;18:56 02/03/2002;
bannerreklame22.mpg;19:20 02/03/2002;
bannerreklame16.mpg;12:56 02/03/2002;
bannerreklame70.mpg;13:20 02/03/2002;


Then why cant you import it into SQL Server with DTS?
Avatar billede thomas_regin Nybegynder
04. april 2002 - 11:44 #2
Hi Terry!

Good point!

I haven't really thought about that. However, my problem is, that I need to be able to run this program every 5 minutes or so. Do you know if DTS can do that?

Thanks,

Thomas.
Avatar billede terry Ekspert
04. april 2002 - 11:45 #3
Yes it can, you make a DTS package and then use the Schedule to set this up!
Avatar billede thomas_regin Nybegynder
04. april 2002 - 11:50 #4
Okay!.. But there's another problem with this procedure that I just thought of. I don't know the name of the textfiles. There will be hundreds of them, and they need to be deleted one by one after the information has been stored in the DB. In VB I would be able to scan a specific folder for files ending with .txt and I don't know if this is possible in DTS!?
Avatar billede terry Ekspert
04. april 2002 - 12:08 #5
I am not sure myslef but I would think it possible in DTS too! Will take a QUICK look and get back
Avatar billede thomas_regin Nybegynder
04. april 2002 - 12:12 #6
Thanks!.. I really appreciate it!!

Thomas.
Avatar billede terry Ekspert
04. april 2002 - 12:20 #7
After a VERY quick look it would be possible to copy the file names ending in for example .txt into a file which you could then import into a table in your SQL dB then you could just loop through the table importing them one at a time.
This is a part of whatI found:

E. Write variable contents out to file
This example writes the contents of the current directory to a file named dir_out.txt in the current server directory.

DECLARE @cmd sysname, @var sysname

SET @var = 'dir /p'

SET @cmd = 'echo ' + @var + ' > dir_out.txt'

EXEC master..xp_cmdshell @cmd


There are more than likely other ways this could be done, tahts just one idea!
Avatar billede thomas_regin Nybegynder
04. april 2002 - 12:53 #8
Where did you find this?.. I have been searching through books online, but I haven't been able to find anything. I have never worked with DTS before, so I need all the help I can get!..

Thomas.
Avatar billede terry Ekspert
04. april 2002 - 13:35 #9
I actually found the dir example by searching for dir in Books online.
In SQL Server 2000 there are over 100 pages concerning DTS.
Enter
DTS Overview and then choose the DTS Overview topic from the list.

In SQL Server 7.0
Enter Overview of Data Transformation Services and againfind this in the topic list
Avatar billede thomas_regin Nybegynder
04. april 2002 - 14:00 #10
Oh my.. There is a lot of reading to do. I think I'll stick with trying to code the Visual Basic App for now. This project has to be finished tomorrow morning, so I'm in a bit of a hurry!

I want to thank you for your very constructive help!! Although you didn't give me the exact solution, you have given me something else to work on in the future!!

If nobody else gives me a solution for this problem, I'll give the points to you!

Thanks again,

Thomas Regin.
Avatar billede thomas_regin Nybegynder
04. april 2002 - 15:16 #11
Terry,

I solved my problem in VB and it works exactly as intended. However, you have been a great help, so I'll give you the points!

Thank you,

Thomas Regin.
Avatar billede terry Ekspert
04. april 2002 - 15:28 #12
thanks :o)
You should take a look at DTS when you have time, it can do MUCH more than you could imagine.

terry
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester