发个VB程序,请帮忙将重要的语句解释一下
Public fMainForm As frmMainPublic gintSmode As Integer 'for service
Public gintPmode As Integer 'for plane
Public gintAmode As Integer 'for airline
Public gintTmode As Integer 'for customertype
Public gintCmode As Integer 'for customer
Public gintKmode As Integer 'for ticket
Sub Main()
Dim fLogin As New frmLogin
fLogin.Show vbModal
If Not fLogin.OK Then
'Login Failed so exit app
End
End If
Unload fLogin
Set fMainForm = New frmMain
fMainForm.Show
End Sub
Public Function ConnectString() _
As String
'returns a DB ConnectString
C
End Function
Public Function ExecuteSQL(ByVal SQL _
As String, MsgString As String) _
As ADODB.Recordset
'executes SQL and returns Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String
On Error GoTo ExecuteSQL_Error
sTokens = Split(SQL)
Set cnn = New ADODB.Connection
cnn.Open ConnectString
If InStr("INSERT,DELETE,UPDATE", _
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
'rst.MoveLast 'get RecordCount
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
Public Sub EnterToTab(Keyasc As Integer)
If Keyasc = 13 Then
SendKeys "{TAB}"
End If
End Sub
Public Function GetRkno() As String
GetRkno = Format(Now, "yymmddhhmmss")
Randomize
GetRkno = GetRkno & Int((99 - 10 + 1) * Rnd + 10)
End Function
[ 本帖最后由 云出无心 于 2007-1-8 22:32 编辑 ] 何谓重要语句? Public Function ExecuteSQL(ByVal SQL _
As String, MsgString As String) _
As ADODB.Recordset
'executes SQL and returns Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String
On Error GoTo ExecuteSQL_Error
sTokens = Split(SQL)
Set cnn = New ADODB.Connection
cnn.Open ConnectString
If InStr("INSERT,DELETE,UPDATE", _
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
'rst.MoveLast 'get RecordCount
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
这段执行数据库的咯~~
我就看不明了
请指教
[ 本帖最后由 云出无心 于 2007-1-8 22:00 编辑 ] 没学VB,不过看明白了 - -#
sTokens = Split(SQL)
Set cnn = New ADODB.Connection
cnn.Open ConnectString
建立数据库链接
If InStr("INSERT,DELETE,UPDATE", _
UCase$(sTokens(0))) Then
cnn.Execute SQL
MsgString = sTokens(0) & _
" query successful"
如果SQL查询语句中含有INSERT DELETE UPDATE等字眼就执行SQL语句并提示执行成功
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, _
adOpenKeyset, _
adLockOptimistic
'rst.MoveLast 'get RecordCount
Set ExecuteSQL = rst
MsgString = "查询到" & rst.RecordCount & _
" 条记录 "
End If
否则(即查询为 select 这种可以返回数据的语句)显示所有查询到的数据
具体VB中的ADODB.Connection 怎么用我就不清楚了,没学过……
如果是看不明白SQL语句
不知是不是废话……
PS:VB不难,找本好书应该轻易就能明白了
再PS:楼主是不是做课程设计要用这些?
如果是这样的话建议查下SQL相关书书籍 谢谢楼上了
不过时间紧急啊~~
明天就检查了~
再衷心感谢一次~~
页:
[1]