简体   繁体   English

ODBC或SQL数据源?

[英]ODBC or SQL DataSource?

I want to connect my VB project to Whatever server is on the same computer. 我想将我的VB项目连接到同一台计算机上的任何服务器。 I want to then interrogate it for the database names. 然后,我想询问它的数据库名称。 SELECT name FROM sys.databases Drop those database names in a drop down. SELECT name FROM sys.databases下拉列表中删除这些数据库名称。 Then change the connection based on the drop down selection. 然后根据下拉选择更改连接。 Is this possible? 这可能吗?

Should I use ODBC or the SQL DataSource? 我应该使用ODBC还是SQL数据源?

Well from what I quickly searched you would use SQL DataSource to connect to an ODBC Database. 从我快速搜索的结果来看,您将使用SQL DataSource连接到ODBC数据库。 No matter, you should always be able to give your users the control to select a database table name and then return them all the data you want from that table. 没关系,您应该始终能够为用户提供选择数据库表名称的控件,然后向他们返回您希望从该表中获取的所有数据。 This can be done with either a nice switch statement as to not trust what the user submits in the form or well actually yeah you should use a switch statement because NEVER TRUST USER INPUT. 可以使用一个不错的switch语句(不信任用户以表单形式提交的内容)来完成此操作,或者实际上,是的,您应该使用switch语句,因为从不信任用户输入。 You could get a little fancy and create a dynamic switch statement generated from a query to the DB of what tables appear in the DB and then add whatever code you need to get the return. 您可能会有点花哨,并创建一个动态switch语句,该语句是由查询生成的,以查询数据库中哪些表出现在数据库中,然后添加所需的任何代码以获取返回值。

Hope that is a point in the correct direction for you. 希望这对您来说是正确的方向。

EDIT switch out table names for Database names, same concept though. EDIT将表名替换为数据库名,尽管概念相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM