Export to excel without using office automation

A

Agnes

I searched from previous post and got that there is a solution which export
the data to export without using Excel auotmation.

However, my database is SQL server, How can I amend objCmd.commandTest ??
I try the following insert statment but fail
"INSERT INTO [Sheet1$] SELECT * FROM
[ODBC;Driver={SQLServer};Server=(210.22.14.201);Database=DTS_ACCOUNT_HK;Trusted_Connection=yes].[arinvinfo];"


// Establish a connection to the data source.(copy from previous post)
System.Data.OleDb.OleDbConnection objConn = new
System.Data.OleDb.OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_strSampleFolder +
"Book7.xls;Extended Properties=Excel 8.0;");
objConn.Open();

// Add two records to the table named 'MyTable'.
System.Data.OleDb.OleDbCommand objCmd = new
System.Data.OleDb.OleDbCommand();
objCmd.Connection = objConn;
objCmd.CommandText = "Insert into MyTable (FirstName, LastName)" +
" values ('Bill', 'Brown')";
objCmd.ExecuteNonQuery();
objCmd.CommandText = "Insert into MyTable (FirstName, LastName)" +
" values ('Joe', 'Thomas')";
objCmd.ExecuteNonQuery();

// Close the connection.
objConn.Close();
 
P

Paul Clement

¤ I searched from previous post and got that there is a solution which export
¤ the data to export without using Excel auotmation.
¤
¤ However, my database is SQL server, How can I amend objCmd.commandTest ??
¤ I try the following insert statment but fail
¤ "INSERT INTO [Sheet1$] SELECT * FROM
¤ [ODBC;Driver={SQLServer};Server=(210.22.14.201);Database=DTS_ACCOUNT_HK;Trusted_Connection=yes].[arinvinfo];"
¤

What is the error?


Paul
~~~~
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top