我有一个excel应用程序,其中按钮单击使用HANA客户端(HDBODBC)连接到HANA数据库,并在获取后将数据放入工作表中。除了具有数据类型为nvarchar(5000)的列的表之外,该方法工作正常。在这种情况下,列值无法正确显示。 例如,我有一个唯一的id自动增量列,它开始显示许多行的0。以下是我正在使用的方法 -
Function importRoutine(sheet As String, provider As String, databaseschema As String, server As String, app As String, row As Long, column As Long, commandText As String, displayname As String, errorFlag As Boolean) As Integer
Debug.Print commandText
Dim l As QueryTable
Dim rs As Object
Dim cnt As ADODB.Connection
Dim cmd As ADODB.Command
Dim iCols As Integer
Set cnt = New ADODB.Connection
Set cmd = New ADODB.Command
Set rcd = New ADODB.Recordset
Dim rangesheet As String
rangesheet = Sheets(sheet).Cells(row + 1, column).Address
Dim connectionsheet As String
connectionsheet = "Driver=" + provider + ";SERVERNODE=" + server + ";" + getAuthentication + "; CS=" + databaseschema + ""
cnt.ConnectionString = connectionsheet
cnt.Open
Set cmd.ActiveConnection = cnt
cmd.commandText = commandText
cmd.CommandType = adCmdText
rcd.Open commandText, cnt '', adOpenStatic
Set rs = CreateObject("ADODB.RECORDSET")
rs.ActiveConnection = cnt
rs.Open commandText, cnt
With Sheets(sheet).ListObjects.Add(SourceType:=3, Source:=rs, Destination:=Range(Sheets(sheet).Cells(row, column).Address)).QueryTable
'.commandText = commandText
'.CommandType = xlCmdSql
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCell
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.ListObject.Name = displayname
.PreserveColumnInfo = False
On Error Resume Next
.Refresh BackgroundQuery:=False
End With
Sheets(sheet).ListObjects(displayname).TableStyle = "TableStyleMedium10"
importRoutine = 0
Call deleteConnection
CloseRecordset:
rs.Close
Set rs = Nothing
CloseConnection:
cnt.Close
Set cnt = Nothing
On Error GoTo 0
End Function
有趣的是,不同的excel版本的nvarchar限制是不同的。 Excel 2010 - 500 Excel - 2013- 3000 Excel - 2016 - 4000 我的问题是每个excel版本的VBA查询表中列的字符数有限制吗?或者我可以改变什么来解决这个问题?
这就是数据的显示方式。您可以检查作为数据库中的标识列的UNIQUE_ID对于许多行显示为0,尽管在数据库中一切正常。