module1.bas

来自「服装销售管理系统」· BAS 代码 · 共 54 行

BAS
54
字号
Attribute VB_Name = "Module1"
Public cn As New ADODB.Connection

'Public rs As New ADODB.Recordset
'Public cmd As New ADODB.command
'cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TDM;Data Source=2NBPC049"


Function Callprocgetrecordset(command As String) As ADODB.Recordset
    Dim cmd As New ADODB.command
    cmd.ActiveConnection = cn
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = command
    Set Callprocgetrecordset = cmd.Execute
    Set cmd = Nothing
End Function

Private Sub main()
    cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TDM;Data Source=2NBPC049"
    cn.Open
    
    MDIForm1.Show
    登陆.Show 1    '启动登陆窗体
    
End Sub

Public Function ExecuteSQL(ByValSQL As String, MsgText As String) As ADODB.Recordset
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cmd As New ADODB.command
Dim sTokens() As String
 On Error GoTo ExecuteSQL_Error
  sTokens = Split(SQL)
Set cnn = New ADODB.Connection
cnn.Open ConnectionString
If InStr("insert,update,delete", UCase$(sTokens(0))) Then
   cnn.Execute SQL
   MsgString = sTokens(0) & "query successful"
Else
  Set rst = New ADODB.Recordset
  rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
  Set ExecuteSQL = rst
  MsgString = "查询到" & rst.RecordCount & "条记录"
End If
ExecuteSQL_Exit:
   Set rst = Nothing
   Set cnn = Nothing
   Exit Function
ExecuteSQL_Error:
   MsgString = "查询错误:" & Err.Description
   Resume ExecuteSQL_Exit
End Function

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?