Conn 没有初始化呀
应该 Conn=new Connection(这里是连接数据库字符串)
给你一个我用的方法:
-----------------------------------------------------
DatabasePath="../db/****.mdb" '数据库路径
MM_Conn_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("" & DatabasePath &"")
set conn=server.CreateObject("adodb.connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("" & DatabasePath &"")
if err then
err.Clear
set conn=nothing
response.write("对不起!数据库连接错误。")
response.End
end if
Function GetRecordset(SQLString)
Dim MM_Recordset_cmd
Set MM_Recordset_cmd = Server.CreateObject ("ADODB.Command")
MM_Recordset_cmd.ActiveConnection = MM_Conn_STRING
MM_Recordset_cmd.CommandText = SQLString
MM_Recordset_cmd.Prepared = true
Set GetRecordset = MM_Recordset_cmd.Execute
End Function
-----------------------------------------------------------------------------------
用这样的方法,在执行时,通常只要:
GetRecordset(SQLString)
调用就可以了。如果需要记录集,则:
Set Myrecordset = GetRecordset(SQLString)
很清楚的用法,通常不会混淆。按“良好的编程习惯”,每次的Open,都必须要Close,开和关是成对出现就最好不过了。
标签:Conn,Execute,SQL