扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:洪晓勐 来源:微软社区 2007年11月9日
关键字:
'作用: 连接SQL Server数据库 '参数:ServerName 服务器名,DBName 数据库名 Public Sub ConnSQLServer(ByVal ServerName As String, ByVal DBName As String) With mCnnDB .ConnectionString = "uid=;pwd= ;driver={SQL Server};" & _ "server=" & ServerName & _ ";database=" & DBName .Open() End With End Sub '作用: 连接SQL Server数据库 '参数:ServerName 服务器名,DBName 数据库名,UserID 用户名,UserPwd 用户密码 Public Sub ConnSQLServer(ByVal ServerName As String, ByVal DBName As String,ByVal UserID As String, ByVal UserPwd As String) With mCnnDB .ConnectionString = "uid=’” & UserID & “’;pwd=’” & UserPwd & _ ”’;driver={SQL Server};" & "server=" & ServerName & _ ";database=" & DBName .Open() End With End Sub |
'作用: 连接Oracle数据库 '参数:ServerName 服务器名,DBName 数据库名,UserID 用户名,UserPwd 用户密码 Public Sub ConnOracle(ByVal ServerName As String, ByVal UserID As String, ByVal UserPwd As String) With mCnnDB .Provider = "MSDAORA" .ConnectionString = "User ID='" & UserID & "';" & "Password='" & UserPwd & _ "';" & "Data Source='" & ServerName & "'" .Open() End With End Sub |
'作用:连接表 '参数:TableName表名 '返回:记录集 Public Function OpenTable(ByVal TableName) As ADODB.Recordset Dim strSql As String Dim rec As ADODB.Recordset rec = New ADODB.Recordset() rec.CursorType = ADODB.CursorTypeEnum.adOpenKeyset rec.LockType = ADODB.LockTypeEnum.adLockOptimistic strSql = "SELECT * FROM " & TableName rec.Open(strSql, mCnnDB) '打开记录集 If Not rec.EOF Then rec.MoveLast() rec.MoveFirst() End If OpenTable = rec End Function |
Public Overloads Function OpenTable(ByVal TableName As String, ByVal strWhere As String) As ADODB.Recordset Dim strSql As String Dim rec As ADODB.Recordset rec = New ADODB.Recordset() rec.CursorType = ADODB.CursorTypeEnum.adOpenKeyset rec.LockType = ADODB.LockTypeEnum.adLockOptimistic strSql = "SELECT * FROM " & TableName & " where " & strWhere rec.Open(strSql, mCnnDB) '打开记录集 If Not rec.EOF Then rec.MoveLast() rec.MoveFirst() End If Return rec End Function |
'作用:连接多表 '参数:strSQL '返回:记录集 Public Function ExecuteSQL(ByVal strSql As String) As ADODB.Recordset Dim rec As New ADODB.Recordset() rec.CursorType = ADODB.CursorTypeEnum.adOpenKeyset rec.LockType = ADODB.LockTypeEnum.adLockOptimistic rec.Open(strSql, mCnnDB) '打开记录集 ExecuteSQL = rec End Function |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者