日期:2014-05-17  浏览次数:21261 次

这两段函数的效率哪个更好?
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注入。