'//连接SQL 模块代码:
Public conn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public addFlag As Boolean
Public Function OpenCn(str_srv As String, str_id As String, str_pwd As String, str_db As String) As Boolean
Dim mag As String
On Error GoTo strerrmag
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Driver={sql server};server=" & Trim(str_srv) & ";uid=" & Trim(str_id) & ";pwd=" & Trim(str_pwd) & ";database=" & Trim(str_db) & ""
conn.ConnectionTimeout = 5
conn.Open
addFlag = True
Exit Function
strerrmag:
mag = "can not connect to sql server !"
Call MsgBox(mag, vbOKOnly + 16, "error")
addFlag = False
Exit Function
End Function
Public Sub cloCn()
On Error Resume Next
If conn.State <> adStateClosed Then conn.Close
Set conn = Nothing
End Sub
Public Sub cloRs()
On Error Resume Next
If rs.State <> adStateClosed Then rs.Clone
Set rs = Nothing
End Sub
//----------------------------------------------
在执行数据插入、更新都没有出错,但执行删除操作时出错(如图)!
'//
Private Sub Cmd_del_Click()
Call OpenCn(Nsqlser.Text, txt_name.Text, txt_pwd.Text, txt_db.Text)
conn.Execute "delete * from my_admin" '//(提示这里出错!)
'//conn.Execute "update my_admin set admin='admin' where id=10"
End Sub
请问各位大侠怎么解决这个问题?