Home All Groups Group Topic Archive Search About
Author
26 Feb 2006 3:45 PM
Agnes
From
http://support.microsoft.com/default.aspx?scid=kb;EN-US;306022#XSLTH4207121122120121120120It
seems we can export the data to an excel by a simple query. However, I try
to amend that statement into "insert int [Sheet1$] select * from myInvoice
", HOwerver, it really doesn't work . Does anyone got idea ?Thanks  alot
'Establish a connection to the data source.
        Dim sConnectionString As String
        sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & sSampleFolder & _
            "Book7.xls;Extended Properties=Excel 8.0;"
        Dim objConn As New
System.Data.OleDb.OleDbConnection(sConnectionString)
        objConn.Open()

        'Add two records to the table.
        Dim objCmd As New System.Data.OleDb.OleDbCommand()
        objCmd.Connection = objConn
        objCmd.CommandText = "Insert into [Sheet1$] (FirstName, LastName)" &
" values ('Bill', 'Brown')" <-- I try to amend
        objCmd.ExecuteNonQuery()
        objCmd.CommandText = "Insert into [Sheet1$] (FirstName, LastName)" &
" values ('Joe', 'Thomas')"
        objCmd.ExecuteNonQuery()

        'Close the connection.
        objConn.Close()

Author
27 Feb 2006 5:12 PM
Paul Clement
On Sun, 26 Feb 2006 23:45:15 +0800, "Agnes" <ag***@dynamictech.com.hk> wrote:

¤ From
¤ http://support.microsoft.com/default.aspx?scid=kb;EN-US;306022#XSLTH4207121122120121120120It
¤ seems we can export the data to an excel by a simple query. However, I try
¤ to amend that statement into "insert int [Sheet1$] select * from myInvoice
¤ ", HOwerver, it really doesn't work . Does anyone got idea ?Thanks  alot
¤ 'Establish a connection to the data source.
¤         Dim sConnectionString As String
¤         sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
¤             "Data Source=" & sSampleFolder & _
¤             "Book7.xls;Extended Properties=Excel 8.0;"
¤         Dim objConn As New
¤ System.Data.OleDb.OleDbConnection(sConnectionString)
¤         objConn.Open()
¤
¤         'Add two records to the table.
¤         Dim objCmd As New System.Data.OleDb.OleDbCommand()
¤         objCmd.Connection = objConn
¤         objCmd.CommandText = "Insert into [Sheet1$] (FirstName, LastName)" &
¤ " values ('Bill', 'Brown')" <-- I try to amend
¤         objCmd.ExecuteNonQuery()
¤         objCmd.CommandText = "Insert into [Sheet1$] (FirstName, LastName)" &
¤ " values ('Joe', 'Thomas')"
¤         objCmd.ExecuteNonQuery()
¤
¤         'Close the connection.
¤         objConn.Close()
¤

What is myInvoice? Is this an Excel Worksheet in the current Workbook opened through your
connection?


Paul
~~~~
Microsoft MVP (Visual Basic)
Author
28 Feb 2006 3:39 AM
Agnes
myInvoice is the table in SQL server,

"Paul Clement" <UseAdddressAtEndofMess***@swspectrum.com>
???????:ijc6021vi5h5k48q4u5krk60abm3r3k***@4ax.com...
Show quoteHide quote
> On Sun, 26 Feb 2006 23:45:15 +0800, "Agnes" <ag***@dynamictech.com.hk>
> wrote:
>
> ¤ From
> ¤
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;306022#XSLTH4207121122120121120120It
> ¤ seems we can export the data to an excel by a simple query. However, I
> try
> ¤ to amend that statement into "insert int [Sheet1$] select * from
> myInvoice
> ¤ ", HOwerver, it really doesn't work . Does anyone got idea ?Thanks  alot
> ¤ 'Establish a connection to the data source.
> ¤         Dim sConnectionString As String
> ¤         sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> ¤             "Data Source=" & sSampleFolder & _
> ¤             "Book7.xls;Extended Properties=Excel 8.0;"
> ¤         Dim objConn As New
> ¤ System.Data.OleDb.OleDbConnection(sConnectionString)
> ¤         objConn.Open()
> ¤
> ¤         'Add two records to the table.
> ¤         Dim objCmd As New System.Data.OleDb.OleDbCommand()
> ¤         objCmd.Connection = objConn
> ¤         objCmd.CommandText = "Insert into [Sheet1$] (FirstName,
> LastName)" &
> ¤ " values ('Bill', 'Brown')" <-- I try to amend
> ¤         objCmd.ExecuteNonQuery()
> ¤         objCmd.CommandText = "Insert into [Sheet1$] (FirstName,
> LastName)" &
> ¤ " values ('Joe', 'Thomas')"
> ¤         objCmd.ExecuteNonQuery()
> ¤
> ¤         'Close the connection.
> ¤         objConn.Close()
> ¤
>
> What is myInvoice? Is this an Excel Worksheet in the current Workbook
> opened through your
> connection?
>
>
> Paul
> ~~~~
> Microsoft MVP (Visual Basic)
Author
28 Feb 2006 2:44 PM
Paul Clement
On Tue, 28 Feb 2006 11:39:17 +0800, "Agnes" <ag***@dynamictech.com.hk> wrote:

¤ myInvoice is the table in SQL server,
¤

You need to hook up with SQL Server as well. See if the following helps:

"INSERT INTO [Sheet1$] SELECT * FROM [ODBC;Driver={SQL
Server};Server=(local);Database=DBName;Trusted_Connection=yes].[myInvoice];"


Paul
~~~~
Microsoft MVP (Visual Basic)