vba ADODB 错误:“没有为一个或多个必需参数提供值”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27622365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ADODB error: 'No value given for one or more required parameters'
提问by lukehawk
I am trying to get some data from another excel spreadsheet, using ADODB and VBA. This is my first attempt at using ADODB, I apologize for my ignorance.
我正在尝试使用 ADODB 和 VBA 从另一个 Excel 电子表格中获取一些数据。这是我第一次尝试使用 ADODB,我为我的无知道歉。
THIS WORKS at pulling all the data from the sheet:
这适用于从工作表中提取所有数据:
rst1.Open "SELECT * FROM [NAVAUM$A1:IU60000];", cnn1, adOpenStatic, adLockReadOnly
THIS WORKS at getting the fields I want, but no Field Names:
这适用于获取我想要的字段,但没有字段名称:
rst1.Open "SELECT F2,F3 FROM [NAVAUM$A2:IU60000] WHERE F1 = 'Return' AND F3 LIKE '" & SearchString & "';", cnn1, adOpenStatic, adLockReadOnly
THIS DOES NOT WORK
这不起作用
rst1.Open "SELECT F2,F3 FROM [NAVAUM$A1:IU60000] WHERE F1 = 'Return' AND F3 LIKE '" & SearchString & "';", cnn1, adOpenStatic, adLockReadOnly
(The difference is the inclusion of row 1, where the field names are.)
(不同之处在于包含第 1 行,即字段名称所在的行。)
It should be noted that row 2 is all blank. (This is how the file comes to me, cannot be changed.) How do I fix this???
需要注意的是,第2行全是空白。(这就是文件给我的方式,无法更改。)我该如何解决这个问题???
EDIT: I GOT THIS!!!
编辑:我明白了!!!
I did not change the query to reflect the fact that I actually have field names now. So, F2 and F3 become [Fund ID] and [Fund Name]. I am not bright.
我没有更改查询以反映我现在实际上拥有字段名称的事实。所以,F2 和 F3 变成了【基金 ID】和【基金名称】。我不亮。
Thanks for knocking the screw loose StackOverflow!!
感谢您将螺丝拧松 StackOverflow !
回答by lukehawk
I figured it out... I did not change the query to reflect the fact that I actually have field names now. So, F2 and F3 become [Fund ID] and [Fund Name]. (F1 is still not named in my data.) I am not bright.
我想通了......我没有更改查询以反映我现在实际上拥有字段名称的事实。所以,F2 和 F3 变成了【基金 ID】和【基金名称】。(F1 在我的数据中仍然没有被命名。)我不聪明。
Thanks for knocking the screw loose StackOverflow!!
感谢您将螺丝拧松 StackOverflow !
THIS...
这个...
rst1.Open "SELECT F2,F3 FROM [NAVAUM$A1:IU60000] WHERE F1 = 'Return' AND F3 LIKE '" & SearchString & "';", cnn1, adOpenStatic, adLockReadOnly
SHOULD BE...
应该...
rst1.Open "SELECT [Fund ID],[Fund Name] FROM [NAVAUM$A1:IU60000] WHERE F1 = 'Return' AND [Fund Name] LIKE '" & SearchString & "';", cnn1, adOpenStatic, adLockReadOnly
Thanks again!
再次感谢!