Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
markiandean
Starting Member
6 Posts |
Posted - 2009-10-12 : 13:24:49
|
Hi all,I am having a small issue with the following code in that it only pastes two columns of data into my excel sheet (there are 10 columns in the table)... can anyone tell me why?Sub QUERYSQLDBANDADDTODB()Dim fCon As ADODB.ConnectionSet fCon = New ADODB.ConnectionDim strSQL As StringfCon.ConnectionString = "Driver={SQL Server Native Client 10.0};Server=CARNA;Database=STOCK_UNIVERSE; Trusted_Connection=yes;"fCon.Open strSQLDim oRS As ADODB.RecordsetSet oRS = New ADODB.RecordsetWith oRS '.ActiveConnection = fCon.Open "SELECT * FROM stock_universe.dbo.Universe"Workbooks("Manage the database.xls").Sheets("Add a stock to the database").Range("B4").CopyFromRecordset oRSEnd WithfCon.CloseSet oRS = NothingSet fCon = NothingEnd SubMy best,Mark |
|
YellowBug
Aged Yak Warrior
616 Posts |
Posted - 2009-10-13 : 07:03:47
|
Is it possible the user executing this query only has access to two columns in the Universe table?Instead of using SELECT *, try SELECT Column1, column2, column3...It is good practise to avoid using SELECT * in your code. |
|
|
markiandean
Starting Member
6 Posts |
Posted - 2009-10-13 : 08:13:08
|
Hi YellowBug,Thanks for the reply, indeed I tried your suggestion and it worked (or sort of). If I take the asterisk out and put the last seven columns in as you suggested it gives me the last 7 columns ok. If I put the first three columns in, it only gives me the first two. By deduction it is therefore the column [InstrumentFullName] that it does not like, which is an ntext column. It stops working when I refer to this column.Will try changing the field type to nvarchar or something similar.Thanks again!M |
|
|
|
|
|