本文整理匯總了VB.NET中System.Data.SqlClient.SqlCommand.Prepare方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET SqlCommand.Prepare方法的具體用法?VB.NET SqlCommand.Prepare怎麽用?VB.NET SqlCommand.Prepare使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.SqlClient.SqlCommand
的用法示例。
在下文中一共展示了SqlCommand.Prepare方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: SqlCommandPrepareEx
Private Sub SqlCommandPrepareEx(ByVal connectionString As String)
Using connection As New SqlConnection(connectionString)
connection.Open()
Dim command As New SqlCommand("", connection)
' Create and prepare an SQL statement.
command.CommandText = _
"INSERT INTO Region (RegionID, RegionDescription) " & _
"VALUES (@id, @desc)"
Dim idParam As SqlParameter = _
New SqlParameter("@id", SqlDbType.Int, 0)
Dim descParam As SqlParameter = _
New SqlParameter("@desc", SqlDbType.Text, 100)
idParam.Value = 20
descParam.Value = "First Region"
command.Parameters.Add(idParam)
command.Parameters.Add(descParam)
' Call Prepare after setting the Commandtext and Parameters.
command.Prepare()
command.ExecuteNonQuery()
' Change parameter values and call ExecuteNonQuery.
command.Parameters(0).Value = 21
command.Parameters(1).Value = "Second Region"
command.ExecuteNonQuery()
End Using
End Sub