首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

这两段函数的效率哪个更好?解决方法

2012-03-11 
这两段函数的效率哪个更好?Public Function Add()Dim strTypestrType 0Set Cmd Server.CreateObject(

这两段函数的效率哪个更好?
Public Function Add()
Dim strType
strType = 0
Set Cmd = Server.CreateObject("ADODB.Command")
oSQL = "InSert Into [HL_News](ClassId,title) Values(?,?)"
With Cmd
.ActiveConnection = Conn
.CommandType = 1
.CommandText = oSQL
.Prepared = True
.Parameters(0).Value = sNewsClassId
.Parameters(1).Value = sNewsTitle  
.Execute strType
End With
Set Cmd = Nothing
Add = strType
End Function



Public Function Add()
sql="select ClassId,title from HL_News"
sql="insert into HL_News(ClassId,title) values("&title&",'"&title&"')"
conn.Execute(sql)
End Function

同样是asp添加代码,这两段代码哪个效率更高?有何区别?


[解决办法]
第二个效率高,参数化查询要多一次查询元数据的过程。不过参数化查询的安全性更高,可以防止SQL注入。

热点排行