如何匹配excel和数据库中的列 [英] How match column from excel and database

查看:99
本文介绍了如何匹配excel和数据库中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库,其中一列是帐户号,并且在Excel工作表中也没有帐号。如何通过vba查询匹配列?



我尝试过:



select * from account where account_no = sheet1.range(A1)



未运行

i have database in which one column is account no and also have account no column in excel sheet. how to match column through vba query ?

What I have tried:

"select * from account where account_no= sheet1.range("A1")"

its not running

推荐答案

你不能只将Excel单元格引用文本放入SQL SELECT命令 - 所有这一切都是将文本传递给SQL,因为它不知道Excel表格是什么,更不用说你是哪一个想要引用,它会引发语法错误,因为它没有名为sheet1的对象。

相反,你需要从该单元格中传递值(最好是作为参数化查询来防止SQL注入问题)已在您的VBA代码中获取它的SQL。
You can't just put the Excel cell reference text into the SQL SELECT Command - all that does is passes the text through to SQL, and since it has no idea what an Excel sheet is, much less which one you want to refer to, it raises an syntax error because it has no object called "sheet1".
Instead, you need to pass the value from that cell (preferably as a parameterised query to prevent SQL Injection problems) to SQL having fetched it in your VBA code.


这篇关于如何匹配excel和数据库中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆