Dim Cmd As New ADODB.Command Dim conn As ADODB.Connection Dim rs As New ADODB.Recordset Set conn = New ADODB.Connection conn.ConnectionString = "Provider=sqlOLEDB;server=192.168.3.51;uid=sa;pwd=sa;Initial Catalog=MyERP" conn.ConnectionTimeout = 50 conn.Open Dim str_0 As String '第一列 Dim str_1 As String '第二列 Dim str_2 As String '第三列 Set rs = conn.Execute("select * from SystemSettingInfo where SettingInfo_Name = '视窗卡'") If rs(0) <> "" Then str_0 = rs(0) str_1 = rs(1) str_2 = rs(2) End If conn.Close
其中,ADODB.Command、ADODB.Connection、ADODB.Recordset可能刚装好的环境声明时没有这些对象,添加这些对象的方法:
选择 “Project(即项目)” --> " References...(即引用)" 打开 References窗口,在列表中找到 “Microsoft ActiceX Data Objects 2.8 Library”项,添加。再声明前面那三个对象就可以找到了。名称中的“2.8”应该是一个版本。还有2.6、2.2等。(我是做项目临时用到了VB。只供新手查看,一般学VB的这些应该都知道。)