|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Ado.net to excel ?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() 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) 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) 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)
How does the community rate .NET 2005 vs. .NET 2003?
Some thoughts on VB9 List.Add method overwriting collectionbase? Set a text in a RowHeader cell academic version [2003] The variable 'GroupBox1' is either undeclared or was never assigned. List all public properties of a Class ? How to move a menu item to the left?! Listbox controls i love reflection:) |
|||||||||||||||||||||||