📄 module1.bas
字号:
Attribute VB_Name = "Module1"
Public Conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public Cmd As New ADODB.Command
'数据查询函数,只需要给出相应的SQL语句,返回一个与函数同名的记录集对象
Public Function ExecuteSQL(ByVal SQL As String) As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
Dim stokens() As String
stokens = Split(SQL)
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\学生信息管理.mdb;Persist Security Info=False"
If InStr("insert,delete,update", UCase$(stokens(0))) Then
cnn.Execute SQL
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
End If
Set ExecuteSQL = rst
End Function
'用来在dgrid网格中显示记录集Rs中的内容
Public Sub Showdata(Rs As ADODB.Recordset, dgrid As MSHFlexGrid)
Dim Rownum As Integer
Rownum = 1
dgrid.Rows = Rownum
dgrid.Cols = Rs.Fields.Count
For j = 0 To Rs.Fields.Count - 1
dgrid.TextMatrix(0, j) = Rs.Fields(j).Name
Next j
Do While Not Rs.EOF
Rownum = Rownum + 1
dgrid.Rows = Rownum
For j = 0 To Rs.Fields.Count - 1
If Not IsNull(Rs.Fields(j).Value) Then
dgrid.TextMatrix(Rownum - 1, j) = Rs.Fields(j).Value
End If
Next j
Rs.MoveNext
Loop
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -