BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Importing CSV file into MS SQL Server 2000

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Tom Woods
Guest





PostPosted: Tue May 08, 2007 12:55 am    Post subject: Importing CSV file into MS SQL Server 2000 Reply with quote



I have a CSV file that I would like to insert all records into an existing
table. I have the following command that is giving me vague parameter
errors.

Can anyone see what I'm doing wrong?

ADOCommand.CommandText := 'INSERT INTO MyDatabase SELECT * FROM
[TEXT;HDR=Yes;Database=F:\MyDirectory\;].[MyCsvFile#csv];';

Thanks,
Tom
Back to top
Del Murray
Guest





PostPosted: Tue May 08, 2007 6:48 am    Post subject: Re: Importing CSV file into MS SQL Server 2000 Reply with quote



See if this gets you a little closer ..

http://msdn2.microsoft.com/en-us/library/ms974559.aspx
Back to top
Brian Bushay TeamB
Guest





PostPosted: Tue May 08, 2007 7:17 am    Post subject: Re: Importing CSV file into MS SQL Server 2000 Reply with quote



Quote:
I have a CSV file that I would like to insert all records into an existing
table. I have the following command that is giving me vague parameter
errors.

Can anyone see what I'm doing wrong?

ADOCommand.CommandText := 'INSERT INTO MyDatabase SELECT * FROM
[TEXT;HDR=Yes;Database=F:\MyDirectory\;].[MyCsvFile#csv];';

try it this way

ADOCommand.CommandText := 'INSERT INTO MyDatabase SELECT * FROM
[MyCsvFile.csv] in "F:\MyDirectory" "Text;HDR=Yes;"
--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com
Back to top
Tom Woods
Guest





PostPosted: Tue May 08, 2007 8:19 pm    Post subject: Re: Importing CSV file into MS SQL Server 2000 Reply with quote

Brian, I tied your suggestion, but it came back with error near key word
"IN", so I tried to use [] instead of "" around the file path.

No matter what I try, I get the following error:

"Parameter object is improperly defined. Inconsistent or incomplete
information was provided"

Any other ideas?

Thanks,
Tom

"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote in message
news:a3nv33lhitberkq40f026d9flvjr5lsghj (AT) 4ax (DOT) com...
Quote:

I have a CSV file that I would like to insert all records into an existing
table. I have the following command that is giving me vague parameter
errors.

Can anyone see what I'm doing wrong?

ADOCommand.CommandText := 'INSERT INTO MyDatabase SELECT * FROM
[TEXT;HDR=Yes;Database=F:\MyDirectory\;].[MyCsvFile#csv];';

try it this way

ADOCommand.CommandText := 'INSERT INTO MyDatabase SELECT * FROM
[MyCsvFile.csv] in "F:\MyDirectory" "Text;HDR=Yes;"
--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com
Back to top
Vassiliev V. V.
Guest





PostPosted: Tue May 08, 2007 8:24 pm    Post subject: Re: Importing CSV file into MS SQL Server 2000 Reply with quote

This syntax is for MS Access. For MS SQL Server 2000 look at BULK INSERT
command in BOL:

BULK INSERT Northwind.dbo.[Order Details]
FROM 'f:\orders\lineitem.tbl'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = ':\n',
FIRE_TRIGGERS
)


//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)


"Tom Woods" <twoods (AT) jamesbaker (DOT) com> сообщил/сообщила в новостях следующее:
news:464094e7$1 (AT) newsgroups (DOT) borland.com...
Quote:
Brian, I tied your suggestion, but it came back with error near key word
"IN", so I tried to use [] instead of "" around the file path.

No matter what I try, I get the following error:

"Parameter object is improperly defined. Inconsistent or incomplete
information was provided"

Any other ideas?

Thanks,
Tom

"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote in message
news:a3nv33lhitberkq40f026d9flvjr5lsghj (AT) 4ax (DOT) com...

I have a CSV file that I would like to insert all records into an
existing
table. I have the following command that is giving me vague parameter
errors.

Can anyone see what I'm doing wrong?

ADOCommand.CommandText := 'INSERT INTO MyDatabase SELECT * FROM
[TEXT;HDR=Yes;Database=F:\MyDirectory\;].[MyCsvFile#csv];';

try it this way

ADOCommand.CommandText := 'INSERT INTO MyDatabase SELECT * FROM
[MyCsvFile.csv] in "F:\MyDirectory" "Text;HDR=Yes;"
--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com

Back to top
Tom Woods
Guest





PostPosted: Wed May 09, 2007 12:12 am    Post subject: Re: Importing CSV file into MS SQL Server 2000 Reply with quote

Del,

Very intersting reading. I'm sure I'll be able to use some of the
information.

Thanks,
Tom


"Del Murray" <Del.Murray (AT) CreditHawk (DOT) Net> wrote in message
news:463fd6b1$1 (AT) newsgroups (DOT) borland.com...
Quote:
See if this gets you a little closer ..

http://msdn2.microsoft.com/en-us/library/ms974559.aspx
Back to top
Tom Woods
Guest





PostPosted: Wed May 09, 2007 12:14 am    Post subject: Re: Importing CSV file into MS SQL Server 2000 Reply with quote

Vassiliev,

It's my understanding that the "From" table or csv file has to be on the
server inorder to perform the BULK INSERT. Needless to say, I was unable to
get the BULK INSERT to work.

Thanks,
Tom


"Vassiliev V. V." <support (AT) oledbdirect (DOT) com> wrote in message
news:46409637 (AT) newsgroups (DOT) borland.com...
Quote:
This syntax is for MS Access. For MS SQL Server 2000 look at BULK INSERT
command in BOL:

BULK INSERT Northwind.dbo.[Order Details]
FROM 'f:\orders\lineitem.tbl'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = ':\n',
FIRE_TRIGGERS
)


//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)


"Tom Woods" <twoods (AT) jamesbaker (DOT) com> сообщил/сообщила в новостях следующее:
news:464094e7$1 (AT) newsgroups (DOT) borland.com...
Brian, I tied your suggestion, but it came back with error near key word
"IN", so I tried to use [] instead of "" around the file path.

No matter what I try, I get the following error:

"Parameter object is improperly defined. Inconsistent or incomplete
information was provided"

Any other ideas?

Thanks,
Tom

"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote in message
news:a3nv33lhitberkq40f026d9flvjr5lsghj (AT) 4ax (DOT) com...

I have a CSV file that I would like to insert all records into an
existing
table. I have the following command that is giving me vague parameter
errors.

Can anyone see what I'm doing wrong?

ADOCommand.CommandText := 'INSERT INTO MyDatabase SELECT * FROM
[TEXT;HDR=Yes;Database=F:\MyDirectory\;].[MyCsvFile#csv];';

try it this way

ADOCommand.CommandText := 'INSERT INTO MyDatabase SELECT * FROM
[MyCsvFile.csv] in "F:\MyDirectory" "Text;HDR=Yes;"
--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com



Back to top
Vassiliev V. V.
Guest





PostPosted: Wed May 09, 2007 8:11 am    Post subject: Re: Importing CSV file into MS SQL Server 2000 Reply with quote

Yes, csv file has to be on server. Any SQL command is executed on server and
can not access files on client computer unless they are shared. But syntax
you try to use is for Microsoft Jet (Access) OLEDB provider only, it will
not work with MS SQL Server. If you need to import csv file located on
client, you will have to write more code, not just execute one SQL command.

//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)



"Tom Woods" <twoods (AT) jamesbaker (DOT) com> сообщил/сообщила в новостях следующее:
news:4640cc27 (AT) newsgroups (DOT) borland.com...
Quote:
Vassiliev,

It's my understanding that the "From" table or csv file has to be on the
server inorder to perform the BULK INSERT. Needless to say, I was unable
to get the BULK INSERT to work.

Thanks,
Tom


"Vassiliev V. V." <support (AT) oledbdirect (DOT) com> wrote in message
news:46409637 (AT) newsgroups (DOT) borland.com...
This syntax is for MS Access. For MS SQL Server 2000 look at BULK INSERT
command in BOL:

BULK INSERT Northwind.dbo.[Order Details]
FROM 'f:\orders\lineitem.tbl'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = ':\n',
FIRE_TRIGGERS
)


//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)


"Tom Woods" <twoods (AT) jamesbaker (DOT) com> сообщил/сообщила в новостях
следующее: news:464094e7$1 (AT) newsgroups (DOT) borland.com...
Brian, I tied your suggestion, but it came back with error near key
word "IN", so I tried to use [] instead of "" around the file path.

No matter what I try, I get the following error:

"Parameter object is improperly defined. Inconsistent or incomplete
information was provided"

Any other ideas?

Thanks,
Tom

"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote in message
news:a3nv33lhitberkq40f026d9flvjr5lsghj (AT) 4ax (DOT) com...

I have a CSV file that I would like to insert all records into an
existing
table. I have the following command that is giving me vague parameter
errors.

Can anyone see what I'm doing wrong?

ADOCommand.CommandText := 'INSERT INTO MyDatabase SELECT * FROM
[TEXT;HDR=Yes;Database=F:\MyDirectory\;].[MyCsvFile#csv];';

try it this way

ADOCommand.CommandText := 'INSERT INTO MyDatabase SELECT * FROM
[MyCsvFile.csv] in "F:\MyDirectory" "Text;HDR=Yes;"
--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com





Back to top
Chris.Cheney
Guest





PostPosted: Wed May 09, 2007 8:11 am    Post subject: Re: Importing CSV file into MS SQL Server 2000 Reply with quote

"Tom Woods" <twoods (AT) jamesbaker (DOT) com> wrote in
news:463f8449 (AT) newsgroups (DOT) borland.com:

Quote:
I have a CSV file that I would like to insert all records into an
existing table. I have the following command that is giving me vague
parameter errors.

Can anyone see what I'm doing wrong?

ADOCommand.CommandText := 'INSERT INTO MyDatabase SELECT * FROM
[TEXT;HDR=Yes;Database=F:\MyDirectory\;].[MyCsvFile#csv];';

Thanks,
Tom

I sympathise with your difficulties - having been there too.

Starting from scratch ...

INSERT INTO inserts into an existing table [sic] in the currently
selected database. Is MyDatabase a database or a table?

Is your ADO connection to SQL Server (SQLOLEDB provider) or to the JET
(or ACE) provider? Your CommandText above implies the latter.

I suggest

1. Connect to SQL Server using the SQLOLEDB provider and select the
appropriate database.

2. If MyTable exists, then use the following command text

INSERT INTO MyTable SELECT * FROM OPENDATASOURCE
('Microsoft.JET.OLEDB.4.0', 'Data Source=F:\MyDirectory;Extended
Properties="text;HDR=No"')...[MyCsvFile#csv]

Replace Microsoft.JET.OLEDB.4.0 with Microsoft.ACE.OLEDB.12.0 if that is
the means of access to the text file that you intend to use. (You could
also access the text file via ODBC, but I have not looked into that yet).

Alternatively, to create and populate MyTable, use

SELECT * INTO MyTable FROM OPENDATASOURCE('Microsoft.JET.OLEDB.4.0',
'Data Source=F:\MyDirectory;Extended Properties="text;HDR=No"')...
[MyCsvFile#csv]

See BOL for details about OPENDATASOURCE

HTH
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.