--------------下面是我的程序代码-----------------------------
Dim tj1 As Boolean
Dim tj2 As Boolean
Dim sqlstr As String
Private Sub Command1_Click()
If tj1 = False And tj2 = False Then
MsgBox "请选择查询条件!", vbExclamation, "警告"
Option1.SetFocus
Exit Sub
End If
If Trim(Text1.Text) = "" Then
MsgBox "请输入查询条件!", vbExclamation, "警告"
Text1.SetFocus
Exit Sub
End If
If tj1 = True Then
sqlstr = "select * from jydm where jydm= '" & Trim(Text1.Text) & "' "
Call viewdata
End If
If tj2 = True Then
sqlstr = "select * from jydm where jypy= '" & Trim(Text1.Text) & "' "
MsgBox sqlstr
Call viewdata
End If
End Sub
Private Sub Form_Load()
tj1 = False
tj2 = False
End Sub
Private Sub Option1_Click()
If Option1.Value = True Then
tj1 = True
tj2 = False
Else
tj1 = False
tj2 = True
End If
End Sub
Private Sub viewdata()
Dim msgtext As String
Dim ret As ADODB.Recordset
Set ret = New ADODB.Recordset
Set ret = executeSQL(sqlstr, msgtext)
With MSFlexGrid1
.TextMatrix(0, 0) = "序号"
.TextMatrix(0, 1) = "交易代码"
.TextMatrix(0, 2) = "交易名称"
.TextMatrix(0, 3) = "交易拼音"
Do While Not ret.EOF
.TextMatrix(.Rows - 1, 0) = .Rows - 1
.TextMatrix(.Rows - 1, 1) = ret.Fields(0)
.TextMatrix(.Rows - 1, 2) = ret.Fields(1)
.TextMatrix(.Rows - 1, 3) = ret.Fields(2)
.Rows = .Rows + 1
ret.MoveNext
Loop
End With
ret.Close
End Sub
Private Sub Option2_Click()
If Option2.Value = True Then
tj2 = True
tj1 = False
Else
tj2 = False
tj1 = True
End If
End Sub
----------------------------------下面是公用模块代码------------------------------------------
Public Function executeSQL(ByVal sqlstr As String, msgstr As String) As ADODB.Recordset
Dim conn As ADODB.Connection
Dim ret As ADODB.Recordset
Dim sTokens() As String
Set conn = New ADODB.Connection
On Error GoTo executeSQL_Error
sTokens = Split(sqlstr)
conn.ConnectionString = "dsn=cxjydm;uid=;pwd="
conn.Open
If InStr("insert,delete,update", LCase(sTokens(0))) Then
conn.executeSQL
msgstr = sTokens(0) & "query successful"
Else
Set ret = New ADODB.Recordset
ret.Open Trim$(sqlstr), conn, adOpenKeyset, adLockOptimistic
Set executeSQL = ret
End If
executeSQL_Exit:
Set ret = Nothing
Set conn = Nothing
Exit Function
executeSQL_Error:
msgstr = "查询错误:" & Err.Description
Resume executeSQL_Exit
End Function
----------------------------------------------------------------------
问题:
1:如果我选择了"按交易代码查询",输入0100,结果查询到了一条记录,
如果我再按按钮,就又会增加一条同样的记录,为什么呀?什么原因导致这样呢?
2:如果我选择了"按拼音查询",输入abc,如果没有查询到记录,可结果记录内容还是[第一个]问题的记录,
按常理说不应该是第一个问题的记录的呀?应该是显示字段名,而不显示记录内容才对的呀?
请大家帮我一下
[此贴子已经被作者于2007-1-6 9:12:39编辑过]