本文介绍了VB.NET 中的预处理语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 vb.net 和 Microsoft SQL Server 2008 中准备好的语句的新手.我真的找不到任何好的来源来通过连接字符串连接到数据库并执行准备好的语句.有人可以向我展示一个示例或向我指出可能有用的资源吗?
I am new to prepared statements in vb.net and Microsoft SQL Server 2008. I can't really find any good sources for connecting to a database via connection string and executing prepared statements. Could someone show me an example or point me to a resource that might be useful?
推荐答案
准备好的语句只不过是包含在事务中的参数化 SqlCommands.
Prepared statements are nothing but Parametrized SqlCommands enclosed in a Transaction.
例如,这是一个准备好的语句:
For example, this is a Prepared Statement:
Using c As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
c.Open()
using mytransaction = c.BeginTransaction()
Dim command = New SqlCommand("INSERT INTO yourtable(image) values (@image)", c)
''# this is specific to the FileUploadControl but the idea is to get the
''#image in a byte array; however you do it, it doesn't matter
Dim buffer(FileUpload1.PostedFile.ContentLength) As Byte
FileUpload1.PostedFile.InputStream.Read(buffer, 0, buffer.Length)
command.Parameters.AddWithValue("@image", buffer)
command.ExecuteNonQuery()
mytransaction .Commit()
End Using
End Using
这篇关于VB.NET 中的预处理语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!