Article ID: 200427
Article Last Modified on 8/11/2005
SELECT * INTO <Target> FROM <Source>Where <Source> is the table we want to copy and <Target> is the destination for the table. Note that this SQL statement will attempt to create <Target> with the same table structure as <Source> and populate <Target> with all of the records from <Source>.
[<Full path to Microsoft Access database>].[<Table Name>] [ODBC;<ODBC Connection String>].[<Table Name>] [<ISAM Name>;<ISAM Connection String>].[<Table Name>]Here are some valid syntax examples:
[c:\mydata\db1.mdb].[Customers] [ODBC;DSN=MyODBCDSN;UID=<username>;PWD=<strong password>;].[authors] [ODBC;Driver=SQL Server;Server=XXX;Database=Pubs;UID=<username>;PWD=<strong password>;].[authors] [Excel 5.0;HDR=Yes;DATABASE=c:\book1.xls;].[Sheet1$]For more information on creating valid Jet connection strings, see the following whitepaper:
#include <afxdao.h> // Needed for MFC DAO classes.
CDaoDatabase db;
CString SQL;
SQL = "SELECT * INTO "
"[Excel 8.0;HDR=Yes;DATABASE=c:\\customers.xls].[Sheet1] "
"FROM [Customers]";
try
{
// Open database and execute SQL statement to copy data.
db.Open( "c:\\nw97.mdb" );
db.Execute( SQL, dbFailOnError );
}
catch( CDaoException * pEX )
{
// Display errors.
AfxMessageBox( pEX->m_pErrorInfo->m_strDescription );
pEX->Delete();
}
#include <afxdao.h> // Needed for MFC DAO classes.
CDaoDatabase db;
CString SQL;
// Change XXX to the name of your SQL Server.
SQL = "SELECT * INTO "
"[LocalAuthors] "
"FROM "
"[ODBC;Driver=SQL Server;SERVER=XXX;DATABASE=Pubs;UID=<username>;PWD=<strong password>;]."
"[authors]";
try
{
// Open database and execute SQL statement to copy data.
db.Open( "c:\\nw97.mdb" );
db.Execute( SQL, dbFailOnError );
}
catch( CDaoException * pEX )
{
// Display errors.
AfxMessageBox( pEX->m_pErrorInfo->m_strDescription );
pEX->Delete();
}
#include <afxdao.h> // Needed for MFC DAO classes.
CDaoDatabase db;
CString SQL;
SQL = "SELECT * INTO "
"[Excel 8.0;HDR=Yes;DATABASE=c:\\customers.xls].[Sheet1] "
"FROM [Customers]";
try
{
// Open database and execute SQL statement to copy data.
db.Open( "c:\\nw97.mdb" );
db.Execute( SQL, dbFailOnError );
}
catch( CDaoException * pEX )
{
// Display errors.
AfxMessageBox( pEX->m_pErrorInfo->m_strDescription );
pEX->Delete();
}
#include <afxdb.h> // Needed for MFC ODBC classes.
CDatabase db;
CString SQL;
// Change XXX to the name of your SQL Server.
SQL = "SELECT * INTO "
"[ODBC;Driver=SQL Server;SERVER=XXX;DATABASE=Pubs;UID=<username>;PWD=<strong password>;]."
"[RemoteShippers] "
"FROM [Shippers]";
try
{
// Open database and execute SQL statement to copy data.
db.OpenEx( "Driver=Microsoft Access Driver (*.mdb);"
"DBQ=c:\\nw97.mdb;", CDatabase::noOdbcDialog );
db.ExecuteSQL( SQL );
}
catch( CDBException* pEX )
{
// Display errors.
AfxMessageBox( pEX->m_strError );
pEX->Delete();
}
Keywords: kbhowto kbdatabase kbjet KB200427