2014-05-13 4 views
0

В настоящее время я пытаюсь получить набор записей в Excel из базы данных, содержащей Azure.Azure извлекает пустой набор записей

Он извлекает правильное количество записей, но записывает их как вкладку - вместо правильных данных. Я могу подтвердить, что запрос, вызываемый в коде, извлекает записи при запросе базы данных.

код ниже:

Dim cnt As New ADODB.Connection 
Dim rst As New ADODB.Recordset 
Dim xlApp As Object 
Dim iLastCellReference As Integer 
Dim recArray As Variant 
Dim strDB As String 
Dim fldCount As Integer 
Dim recCount As Long 
Dim iCol As Integer 
Dim iRow As Integer 
Dim sRange As String 

' Set the string to the path of your database 
strDB = Connection.Range("A2").Value 
On Error GoTo ErrorHandler 
' Open connection to the database 
cnt.Open strDB 


' Open recordset based on Project_Information table 
rst.Open "Select DISTINCT Project_Current_Name From psruser.Project_Master_Table where Project_Enabled = 'True'", cnt 
'rst.Open "Select DISTINCT Project_Number From mruser.Project_Information", cnt 

If Not (rst.BOF And rst.EOF) Then 

' Create an instance of Excel and add a workbook 
Set xlApp = CreateObject("Excel.Application") 

' Copy field names to the first row of the worksheet 
fldCount = rst.Fields.Count 

For iCol = 1 To fldCount 
Parameters.Cells(82, iCol).Value = rst.Fields(iCol - 1).Name 
Next 

' Below is to get the number of rows 
' Copy recordset to an array 
recArray = rst.GetRows 

'Note: GetRows returns a 0-based array where the first 
'dimension contains fields and the second dimension 
'contains records. We will transpose this array so that 
'the first dimension contains records, allowing the 
'data to appears properly when copied to Excel 

' Determine number of records 
recCount = UBound(recArray, 2) + 1 '+ 1 since 0-based array 

' Copy the recordset to the worksheet, starting in cell A132 
' Check the array for contents that are not valid when 
' copying the array to an Excel worksheet 
For iCol = 0 To fldCount - 1 
For iRow = 0 To recCount - 1 
    ' Take care of Date fields 
    If IsDate(recArray(iCol, iRow)) Then 
     recArray(iCol, iRow) = Format(recArray(iCol, iRow)) 
    ' Take care of OLE object fields or array fields 
    Else 
     If IsArray(recArray(iCol, iRow)) Then 
      recArray(iCol, iRow) = "Array Field" 
     End If 
    End If 
'Next iRow 'next record 
Next iRow 
'Next iCol 'next field 
Next iCol 

' Transpose and Copy the array to the worksheet, starting in cell A132 
Parameters.Cells(82, 1).Resize(recCount, fldCount).Value = _ 
TransposeDim(recArray) 

' Close ADO objects 
rst.Close 
cnt.Close 
Set rst = Nothing 
Set cnt = Nothing 
+0

После открытия вашего набора записей, если вы просто используете 'CopyFromRecordset', вы видите какие-либо записи? –

ответ

0

Оказывается, это была строка соединения, то Windows Azure генерироваться строки странные поведения в лучшем случае, это позволят вставки и обновление записей, и выполнения хранимых процедур, но не запрос разобрался.

Я настоятельно рекомендую вам писать свои собственные строки подключения, а не использовать Azure!

Смежные вопросы