 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Tom Woods Guest
|
Posted: Tue May 08, 2007 12:55 am Post subject: Importing CSV file into MS SQL Server 2000 |
|
|
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
|
|
| Back to top |
|
 |
Brian Bushay TeamB Guest
|
Posted: Tue May 08, 2007 7:17 am Post subject: Re: Importing CSV file into MS SQL Server 2000 |
|
|
| 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
|
Posted: Tue May 08, 2007 8:19 pm Post subject: Re: Importing CSV file into MS SQL Server 2000 |
|
|
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
|
Posted: Tue May 08, 2007 8:24 pm Post subject: Re: Importing CSV file into MS SQL Server 2000 |
|
|
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
|
Posted: Wed May 09, 2007 12:12 am Post subject: Re: Importing CSV file into MS SQL Server 2000 |
|
|
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...
|
|
| Back to top |
|
 |
Tom Woods Guest
|
Posted: Wed May 09, 2007 12:14 am Post subject: Re: Importing CSV file into MS SQL Server 2000 |
|
|
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
|
Posted: Wed May 09, 2007 8:11 am Post subject: Re: Importing CSV file into MS SQL Server 2000 |
|
|
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
|
Posted: Wed May 09, 2007 8:11 am Post subject: Re: Importing CSV file into MS SQL Server 2000 |
|
|
"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 |
|
 |
|
|
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
|
|