<%
'ÔÚÖ¸¶¨µÄÊý¾Ý¿âÉÏÔËÐÐSQLÓï¾äµÄÀà
'ʹÓ÷½·¨£º
'dim runs
'set runs=new runsql
'runs.setdbn=Êý¾Ý¿âÃû
'if runs.ifok then
' response.write runs.errs
' response.end
'end if
'runs.setsql=sql
'runs.run
'if runs.ifok then
' response.write runs.errs
' response.end
'else
' response.write "Ö´Ðгɹ¦"
'end if
on error resume next
class runsql
private dbname 'Êý¾Ý¿âÃû
private sql 'ÒªÖ´ÐеÄSQLÓï¾ä
private ifsure 'ÓÃÀ´±£´æÊÇ·ñ³É¹¦µÄ±êÖ¾£¬Èç¹û³É¹¦ÖµÎªfalse£¬Ê§°ÜΪtrue,³õֵΪtrue
private errstr '±£´æËµÃ÷´íÎóµÄÎÄ×Ö
'»ñÈ¡ifsureÖµ
property get ifok()
ifok=ifsure
end property
'»ñÈ¡errstrÖµ
property get errs()
errs=errstr
end property
'
private sub class_initialize()
'ÉèÖÃifsure,errstrµÄ³õÖµ
ifsure=true
errstr="¶ÔÖ¸µãÊý¾Ý¿âÖ´ÐÐSQLÓï¾ä"
end sub
'¸ødbname¸³Öµ
property let setdbn(dbn)
dbname=dbn
ifexistdb dbn
end property
'¸øSQL¸³Öµ
property let setsql(s)
sql=s
end property
'Ö´ÐвÙ×÷
public sub run()
'»¹ÔÀà״̬
class_initialize
'¼ì²é²ÎÊýÊÇ·ñÒѾÌîдÍêÕû
if isnull(dbname) or isempty(dbname) or cstr(dbname)="" then
errstr="dbname²»ÄÜΪ¿Õ"
exit sub
end if
if isnull(sql) or isempty(sql) or cstr(sql)="" then
errstr="sql²»ÄÜΪ¿Õ"
exit sub
end if
dim conn 'Á¬½ÓÊý¾Ý¿â¶ÔÏó
set conn=Server.CreateObject("adodb.connection")
if err.number<>0 then
errstr="½¨Á¢adodb.connection¶ÔÏñʧ°Ü."
set objcreate=nothing
exit sub
end if
errstr="²»ÄÜÁ¬½ÓÊý¾Ý¿â"
'Á¬½ÓÊý¾Ý¿â
conn.connectionstring="provider=microsoft.jet.oledb.4.0;data source="+server.mappath(dbname)
conn.open
errstr="Ö´ÐÐSQLÓï¾äʧ°Ü"
'Ö´ÐÐSQLÓï¾ä
conn.execute(sql)
'Èç¹ûû³ö´í ÉèÖóɹ¦±êÖ¾
if err.number=0 then
ifsure=false
end if
end sub
private sub ifexistdb(byval dbn)
'»¹ÔÀà״̬
class_initialize
'Èç¹ûÊý¾Ý¿â´æÔÚ£¬¾ÍÉèΪtrue£¬ÒòΪÈç¹û²»´æÔڵϰ¾Í²»ÄܼÌÐøÖ´ÐÐÕâ¸öÀà
'¼ì²éÊý¾Ý¿âÊÇ·ñÒѾ´æÔÚ
errstr="Êý¾Ý¿â²»´æÔÚ"
dim conn
set conn=server.createobject("adodb.connection")
conn.connectionstring="provider=microsoft.jet.oledb.4.0;data source="+server.mappath(dbn)
conn.open
if err.number=0 then
ifsure=false
end if
end sub
end class
%>

