vba 关于vba中dsn字符串的查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1123699/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:35:50  来源:igfitidea点击:

Query regarding dsn string in vba

sqlformsvbalistboxaccess-vba

提问by SmartestVEGA

Below is the code to fill a list box in a VBA application :

下面是在 VBA 应用程序中填充列表框的代码:

Private Sub Form_Open(Cancel As Integer)

  ''#Populate list box control.
  Dim cnn As ADODB.Connection
  Dim strSQL As String
  Dim rst As ADODB.Recordset
  Dim strList As String

  On Error GoTo ErrHandler

  ''#Use DSN to Northwind. 
  ''#Modify connection and connection string as needed.

  Set cnn = New ADODB.Connection
  cnn.Open "DSN=NorthwindExample"
  strSQL = "SELECT * FROM Shippers"
  Set rst = New ADODB.Recordset
  rst.Open strSQL, cnn
  strList = rst.GetString(adClipString, , ";", ",")

  Debug.Print strList

  Me.lstShippers.RowSource = strList
  rst.Close
  cnn.Close
  Set rst = Nothing
  Set cnn = Nothing

  Exit Sub

ErrHandler:
  MsgBox Err.No & ": " & Err.Description, vbOKOnly, "Error"
  Set rst = Nothing
  Set cnn = Nothing
End Sub

I need to know what i need to put as DSN string? Where will I get the info?

我需要知道我需要把什么作为 DSN 字符串?我从哪里得到信息?

What is adClipStringhere in this code?

什么是adClipString这里的代码?

Is there any option to populate list control without using DSN connection object since I am taking the values from the same access table?

是否有任何选项可以在不使用 DSN 连接对象的情况下填充列表控件,因为我从同一个访问表中获取值?

采纳答案by Lima

Here is a link that contains the different connection strings for Access: http://www.connectionstrings.com/access

这是一个包含 Access 不同连接字符串的链接:http: //www.connectionstrings.com/access

Something like this should work: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;

这样的事情应该可以工作:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;

Im not sure what adClipString is, it could be an undeclared variable or database column?

我不确定 adClipString 是什么,它可能是一个未声明的变量或数据库列?

Matt

马特

回答by shahkalpesh

Hereis the info on adClipString.

是有关 adClipString 的信息。

Basically, GetString method gets the content of the entire recordset into a string variable where columns will be separated by ";" and rows will be separated by "," (as per your code).

基本上,GetString 方法将整个记录集的内容放入一个字符串变量中,其中的列将用“;”分隔。和行将用“,”分隔(根据您的代码)。

Regarding DSN - see Start -> Settings -> Control Panel -> Administrative Tools -> Data Sources (ODBC). One of the tab (I guess System DSN) is where ODBC based data source can be created and are listed.

关于 DSN - 请参阅开始 -> 设置 -> 控制面板 -> 管理工具 -> 数据源 (ODBC)。选项卡之一(我猜是系统 DSN)是可以创建和列出基于 ODBC 的数据源的地方。