我学vb快一年了,总觉得自己成长地太慢,非常郁闷!最近写了一个学籍管理程序,不是很好,其中有很多东西不行,比如说记录集的使用经常出错,激活了一个修改界面之后再去查询界面就会把记录固定在一条上。下面是我写的模块的代码,大家看看,欢迎指正!
Public conn As ADODB.Connection Public cmd As ADODB.Command Public myreset As ADODB.Recordset Public mysql As String Public flag As Integer '记录用户级别 Public Username As String '记录用户名 Public Function Sqlexec(sql As String) As Boolean On Error GoTo err Set conn = New ADODB.Connection Set cmd = New ADODB.Command Set myreset = New ADODB.Recordset conn.ConnectionString = "dsn=stuinf" conn.Open 'cmd.ActiveConnection = conn 'cmd.CommandText = sql myreset.CursorType = adOpenKeyset myreset.LockType = adLockBatchOptimistic myreset.CursorLocation = adUseClient myreset.Open sql, conn 'Set rstEmployees = New ADODB.Recordset ' rstEmployees.CursorType = adOpenKeyset ' rstEmployees.LockType = adLockOptimistic ' rstEmployees.Open "employee", cnn1, , , adCmdTable 'Set myreset = cmd.Execute() Sqlexec = True Exit Function err: For Each e In conn.Errors MsgBox e.Description Next Sqlexec = False End Function