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 

How to copy records from a SQL Server Table to a Access Tabl

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
luo
Guest





PostPosted: Tue May 11, 2004 3:23 am    Post subject: How to copy records from a SQL Server Table to a Access Tabl Reply with quote



can i use SQL?
or anthing else?


Back to top
George Christoforakis
Guest





PostPosted: Tue May 11, 2004 6:05 am    Post subject: Re: How to copy records from a SQL Server Table to a Access Reply with quote



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





PostPosted: Tue May 11, 2004 6:35 am    Post subject: Re: How to copy records from a SQL Server Table to a Access Reply with quote



but how to get this with delphi?


Back to top
David Lewis
Guest





PostPosted: Tue May 11, 2004 8:09 am    Post subject: Re: How to copy records from a SQL Server Table to a Access Reply with quote

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





PostPosted: Tue May 11, 2004 8:14 am    Post subject: Re: How to copy records from a SQL Server Table to a Access Reply with quote

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





PostPosted: Tue May 11, 2004 3:15 pm    Post subject: Re: How to copy records from a SQL Server Table to a Access Reply with 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...
Quote:
can i use SQL?
or anthing else?





Back to top
Vitali Kalinin
Guest





PostPosted: Tue May 11, 2004 3:17 pm    Post subject: Re: How to copy records from a SQL Server Table to a Access Reply with quote

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





PostPosted: Tue May 11, 2004 6:39 pm    Post subject: Re: How to copy records from a SQL Server Table to a Access Reply with 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...
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





PostPosted: Wed May 12, 2004 8:55 am    Post subject: Re: How to copy records from a SQL Server Table to a Access Reply with quote

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





PostPosted: Mon May 17, 2004 10:31 am    Post subject: Re: How to copy records from a SQL Server Table to a Access Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) 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.