Public SqlConn As ADODB.ConnectionPublic sConn As String
Public Sub OpenConn() If SqlConn Is Nothing = True Then '建立数据库连接对象 Set SqlConn = New ADODB.Connection End If If SqlConn.State <> 1 Then '打开数据库连接 SqlConn.Open sConn End IfEnd Sub
Public Sub CloseConn() '如果数据库连接对象不为空则关闭数据库连接 If SqlConn.State = 1 Then SqlConn.Close End IfEnd Sub
Public Function RunSelectSQL(ByVal sSQLString As String) As ADODB.Recordset Dim rs As New Recordset '打开数据库连接 Me.OpenConn '执行SQL操作 rs.Open sSQLString, SqlConn, adOpenStatic, adLockReadOnly Set RunSelectSQL = rsEnd Function
Public Function RunSelectSQLUpdatable(ByVal sSQLString As String) As ADODB.Recordset Dim rs As New Recordset '打开数据库连接 Me.OpenConn '执行SQL操作 rs.Open sSQLString, SqlConn, adOpenStatic, adLockBatchOptimistic Set RunSelectSQLUpdatable = rsEnd Function
Private Sub Class_Initialize() sConn = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=jxclink"End Sub
怎么运行一直说截图的问题?谢谢
问下VB连sql问题
答案:2 悬赏:50 手机版
解决时间 2021-03-16 04:40
- 提问者网友:两耳就是菩提
- 2021-03-15 17:36
最佳答案
- 五星知识达人网友:独钓一江月
- 2021-03-15 19:15
ADO 的方式访问SQL 数据库的字符串如下:
Conn="Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa; Password=xxx; Data Source =服务器名;Initial Catalog=数据库名;"
似乎你的连接字符串有些问题!
Conn="Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa; Password=xxx; Data Source =服务器名;Initial Catalog=数据库名;"
似乎你的连接字符串有些问题!
全部回答
- 1楼网友:患得患失的劫
- 2021-03-15 19:39
sql语句错误:
call openrs("select * from cmub where 日期 between '" & text1.text & "' and '" & text2.text & "'" & kku)
改为这样
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯