 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
luo Guest
|
Posted: Tue May 11, 2004 3:23 am Post subject: How to copy records from a SQL Server Table to a Access Tabl |
|
|
can i use SQL?
or anthing else?
|
|
| Back to top |
|
 |
George Christoforakis Guest
|
Posted: Tue May 11, 2004 6:05 am Post subject: Re: How to copy records from a SQL Server Table to a Access |
|
|
I would use the DTS from the mssql.
George Christoforakis
"luo" <big1uo (AT) 21cn (DOT) com> wrote
| Quote: | can i use SQL?
or anthing else?
|
|
|
| Back to top |
|
 |
luo Guest
|
Posted: Tue May 11, 2004 6:35 am Post subject: Re: How to copy records from a SQL Server Table to a Access |
|
|
but how to get this with delphi?
|
|
| Back to top |
|
 |
David Lewis Guest
|
Posted: Tue May 11, 2004 8:09 am Post subject: Re: How to copy records from a SQL Server Table to a Access |
|
|
Are you trying to do this automatically, or manually ? If manual, then all
you need is an ODBC connection to SQL Server and then link the SQL Server
tables within access itself. Open the SQL Server table, copy and paste to
access. If you want to do it automatically, then you could actually do the
same with Access macros - but I don't know the commands. If you are trying
to do it in Delphi, then you just need 2 BDE aliases, one to Access and the
other to SQL Server, then have 2 TDatabase components in your Delphi project
to open each one and then use TTables / TQueries to get data from one and
post to the other.
"luo" <big1uo (AT) 21cn (DOT) com> wrote
| Quote: | can i use SQL?
or anthing else?
|
|
|
| Back to top |
|
 |
Jeremy Collins Guest
|
Posted: Tue May 11, 2004 8:14 am Post subject: Re: How to copy records from a SQL Server Table to a Access |
|
|
luo wrote:
| Quote: | but how to get this with delphi?
|
Import the DTS type library into your project, and
Google for examples (I've posted a couple).
--
jc
Remove the -not from email
|
|
| Back to top |
|
 |
Vitali Kalinin Guest
|
Posted: Tue May 11, 2004 3:15 pm Post subject: Re: How to copy records from a SQL Server Table to a Access |
|
|
This procedure does the trick:
procedure MoveTableFromODBC2Access(MDBConnection : TADOConnection;
const AConnectionString, ATableName : string);
var
ACatalog : _Catalog;
ATable : _Table;
begin
ACatalog := CoCatalog.Create;
ACatalog.Set_ActiveConnection(MDBConnection.ConnectionObject);
ATable := CoTable.Create;
ATable.ParentCatalog := ACatalog;
ATable.Name := 'SourceTable';
ATable.Properties['Jet OLEDB:Create Link'].Value := True;
ATable.Properties['Jet OLEDB:Link Provider String'].Value :=
AConnectionString;
ATable.Properties['Jet OLEDB:Remote Table Name'].Value := ATableName;
ACatalog.Tables.Append(ATable);
MDBConnection.Execute('SELECT * INTO ' + ATableName + ' FROM
SourceTable');
MDBConnection.Execute('DROP TABLE SourceTable');
end;
Assumptions: MDBConnection is connected to mdb file and active. Target mdb
file doesn't have tables with name [SourceTable] and value passed in
ATableName.
Example of usage:
MoveTableFromODBC2Access(MDBConnection, 'ODBC;DRIVER=SQL
Server;SERVER=(local);DATABASE=Northwind', 'Products');//Windows integrated
security
MoveTableFromODBC2Access(MDBConnection, 'ODBC;DRIVER=SQL
Server;SERVER=(local);UID=sa;PWD=simsim;DATABASE=Northwind',
'Products');//MS SQL Server security
Regards,
Vitali
"luo" <big1uo (AT) 21cn (DOT) com> сообщил/сообщила в новостях следующее:
news:40a04722$1 (AT) newsgroups (DOT) borland.com...
| Quote: | can i use SQL?
or anthing else?
|
|
|
| Back to top |
|
 |
Vitali Kalinin Guest
|
Posted: Tue May 11, 2004 3:17 pm Post subject: Re: How to copy records from a SQL Server Table to a Access |
|
|
Forgot to mention you will need to import ADOX type library and append it to
uses clause.
"Vitali Kalinin" <vitkalinin (AT) yahoo (DOT) com> сообщил/сообщила в новостях
следующее: news:40a0ee3e (AT) newsgroups (DOT) borland.com...
| Quote: | This procedure does the trick:
procedure MoveTableFromODBC2Access(MDBConnection : TADOConnection;
const AConnectionString, ATableName : string);
var
ACatalog : _Catalog;
ATable : _Table;
begin
ACatalog := CoCatalog.Create;
ACatalog.Set_ActiveConnection(MDBConnection.ConnectionObject);
ATable := CoTable.Create;
ATable.ParentCatalog := ACatalog;
ATable.Name := 'SourceTable';
ATable.Properties['Jet OLEDB:Create Link'].Value := True;
ATable.Properties['Jet OLEDB:Link Provider String'].Value :=
AConnectionString;
ATable.Properties['Jet OLEDB:Remote Table Name'].Value := ATableName;
ACatalog.Tables.Append(ATable);
MDBConnection.Execute('SELECT * INTO ' + ATableName + ' FROM
SourceTable');
MDBConnection.Execute('DROP TABLE SourceTable');
end;
Assumptions: MDBConnection is connected to mdb file and active. Target mdb
file doesn't have tables with name [SourceTable] and value passed in
ATableName.
Example of usage:
MoveTableFromODBC2Access(MDBConnection, 'ODBC;DRIVER=SQL
Server;SERVER=(local);DATABASE=Northwind', 'Products');//Windows
integrated
security
MoveTableFromODBC2Access(MDBConnection, 'ODBC;DRIVER=SQL
Server;SERVER=(local);UID=sa;PWD=simsim;DATABASE=Northwind',
'Products');//MS SQL Server security
Regards,
Vitali
"luo" <big1uo (AT) 21cn (DOT) com> сообщил/сообщила в новостях следующее:
news:40a04722$1 (AT) newsgroups (DOT) borland.com...
can i use SQL?
or anthing else?
|
|
|
| Back to top |
|
 |
Viatcheslav V. Vassiliev Guest
|
Posted: Tue May 11, 2004 6:39 pm Post subject: Re: How to copy records from a SQL Server Table to a Access |
|
|
Even easer:
cmd := 'SELECT * INTO [authors] FROM [ODBC;DRIVER=SQL
Server;SERVER=(local);DATABASE=pubs;].[authors]';
ADOConnection1.Execute(cmd, RecAffected);
Generally it should be better to enclose table name into brackets:
'SELECT * INTO [' + ATableName + '] FROM '....
//------------------------------------------
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)
"Vitali Kalinin" <vitkalinin (AT) yahoo (DOT) com> сообщил/сообщила в новостях
следующее: news:40a0ee3e (AT) newsgroups (DOT) borland.com...
| Quote: | This procedure does the trick:
procedure MoveTableFromODBC2Access(MDBConnection : TADOConnection;
const AConnectionString, ATableName : string);
var
ACatalog : _Catalog;
ATable : _Table;
begin
ACatalog := CoCatalog.Create;
ACatalog.Set_ActiveConnection(MDBConnection.ConnectionObject);
ATable := CoTable.Create;
ATable.ParentCatalog := ACatalog;
ATable.Name := 'SourceTable';
ATable.Properties['Jet OLEDB:Create Link'].Value := True;
ATable.Properties['Jet OLEDB:Link Provider String'].Value :=
AConnectionString;
ATable.Properties['Jet OLEDB:Remote Table Name'].Value := ATableName;
ACatalog.Tables.Append(ATable);
MDBConnection.Execute('SELECT * INTO ' + ATableName + ' FROM
SourceTable');
MDBConnection.Execute('DROP TABLE SourceTable');
end;
Assumptions: MDBConnection is connected to mdb file and active. Target mdb
file doesn't have tables with name [SourceTable] and value passed in
ATableName.
Example of usage:
MoveTableFromODBC2Access(MDBConnection, 'ODBC;DRIVER=SQL
Server;SERVER=(local);DATABASE=Northwind', 'Products');//Windows
integrated
security
MoveTableFromODBC2Access(MDBConnection, 'ODBC;DRIVER=SQL
Server;SERVER=(local);UID=sa;PWD=simsim;DATABASE=Northwind',
'Products');//MS SQL Server security
Regards,
Vitali
"luo" <big1uo (AT) 21cn (DOT) com> сообщил/сообщила в новостях следующее:
news:40a04722$1 (AT) newsgroups (DOT) borland.com...
can i use SQL?
or anthing else?
|
|
|
| Back to top |
|
 |
Vitali Kalinin Guest
|
Posted: Wed May 12, 2004 8:55 am Post subject: Re: How to copy records from a SQL Server Table to a Access |
|
|
Very neat!
"Viatcheslav V. Vassiliev" <support (AT) oledbdirect (DOT) com> сообщил/сообщила в
новостях следующее: news:40a11dd4 (AT) newsgroups (DOT) borland.com...
| Quote: | Even easer:
cmd := 'SELECT * INTO [authors] FROM [ODBC;DRIVER=SQL
Server;SERVER=(local);DATABASE=pubs;].[authors]';
ADOConnection1.Execute(cmd, RecAffected);
Generally it should be better to enclose table name into brackets:
'SELECT * INTO [' + ATableName + '] FROM '....
//------------------------------------------
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)
"Vitali Kalinin" <vitkalinin (AT) yahoo (DOT) com> сообщил/сообщила в новостях
следующее: news:40a0ee3e (AT) newsgroups (DOT) borland.com...
This procedure does the trick:
procedure MoveTableFromODBC2Access(MDBConnection : TADOConnection;
const AConnectionString, ATableName : string);
var
ACatalog : _Catalog;
ATable : _Table;
begin
ACatalog := CoCatalog.Create;
ACatalog.Set_ActiveConnection(MDBConnection.ConnectionObject);
ATable := CoTable.Create;
ATable.ParentCatalog := ACatalog;
ATable.Name := 'SourceTable';
ATable.Properties['Jet OLEDB:Create Link'].Value := True;
ATable.Properties['Jet OLEDB:Link Provider String'].Value :=
AConnectionString;
ATable.Properties['Jet OLEDB:Remote Table Name'].Value := ATableName;
ACatalog.Tables.Append(ATable);
MDBConnection.Execute('SELECT * INTO ' + ATableName + ' FROM
SourceTable');
MDBConnection.Execute('DROP TABLE SourceTable');
end;
Assumptions: MDBConnection is connected to mdb file and active. Target
mdb
file doesn't have tables with name [SourceTable] and value passed in
ATableName.
Example of usage:
MoveTableFromODBC2Access(MDBConnection, 'ODBC;DRIVER=SQL
Server;SERVER=(local);DATABASE=Northwind', 'Products');//Windows
integrated
security
MoveTableFromODBC2Access(MDBConnection, 'ODBC;DRIVER=SQL
Server;SERVER=(local);UID=sa;PWD=simsim;DATABASE=Northwind',
'Products');//MS SQL Server security
Regards,
Vitali
"luo" <big1uo (AT) 21cn (DOT) com> сообщил/сообщила в новостях следующее:
news:40a04722$1 (AT) newsgroups (DOT) borland.com...
can i use SQL?
or anthing else?
|
|
|
| Back to top |
|
 |
Asim Guest
|
Posted: Mon May 17, 2004 10:31 am Post subject: Re: How to copy records from a SQL Server Table to a Access |
|
|
| Quote: | thanks a lot!
Try Using BatchMove Component of BDE which takes a Source and Destination |
Dataset for data transfer.
HTH,
Asim Khan
--- posted by geoForum on http://delphi.newswhat.com
|
|
| 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
|
|