gpt4 book ai didi

sql - 如何使用adodb编写sql查询来选择长度超过255个字符的数据

转载 作者:行者123 更新时间:2023-12-02 22:09:59 28 4
gpt4 key购买 nike

我正在使用ADODB连接编写SQL语句来提取excel vba中的数据。

我的问题是我有一个单元格,其中包含长度超过 255 个字符的字符串。

我想知道是否有办法继续使用 ADODB 连接来选择长度超过 255 个字符的数据

这是我使用的功能。

Public Function QueryRead(sqlArg As String) As Dictionary

Dim pConnection As ADODB.Connection
Set pConnection = New ADODB.Connection

With pConnection
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & ActiveWorkbook.FullName & _
";Extended Properties=Excel 8.0;"
'.Provider = "MSDASQL"
'.ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};" & _
"DBQ=" & App.Path & "\ExcelSrc.xls; "
.CursorLocation = adUseClient
.Open
End With

Dim pMap As New ADODB.Recordset

Dim sql As String
sql = sqlArg

Dim resultSet As New Dictionary

pMap.Open sql, pConnection
If pMap.RecordCount > 0 Then

Dim record As Variant

Dim counter As Integer
counter = 0

Do Until pMap.EOF

Dim resultRecord As Dictionary

Set resultRecord = New Dictionary

For Each record In pMap.fields

resultRecord.Add record.Name, record.value
Next
Dim index As String
index = CStr(counter)
resultSet.Add index, resultRecord
counter = counter + 1
pMap.MoveNext
Loop

End If

pMap.Close
pConnection.Close

Set QueryRead = resultSet

End Function

我就是这样调用它的

Set resultSet = model.QueryRead("SELECT * FROM [Database$] WHERE [Level] = 2 AND [Item_No] = '" & itemNo & "'")

我的工作表称为“数据库”,它具有“级别”和“项目编号”等列。

“公式”列下的一个单元格的字符串长度超过 255 个字符。

请指教。

更新

我想强调的是

a) 是提取出来的单个字段数据超过 255 个字符的限制。意思是说,“SELECT * FROM”中的*

b) 这不是我的输入参数超过 255 个字符

c) 这不是我的查询字符串超过 255 个字符

最佳答案

由于您使用的是 Excel 2003 和更早版本的连接字符串,因此 Microsoft support article适用。如果数据的前 8 行中没有任何值超过 255 个字符,则所有值都将被截断为 255 个字符。

一个简单的解决方法可能是确保工作表上的第一个数据行始终包含长度超过 255 个字符的值 - 要么是您稍后丢弃的虚拟行,要么是您确保最终出现在该行中的真实数据值。

您可以将扫描的行数调整为最多 16,但这并不能真正解决问题

关于sql - 如何使用adodb编写sql查询来选择长度超过255个字符的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13695378/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com