本文整理汇总了VB.NET中System.Data.SqlClient.SqlParameterCollection.AddWithValue方法的典型用法代码示例。如果您正苦于以下问题:VB.NET SqlParameterCollection.AddWithValue方法的具体用法?VB.NET SqlParameterCollection.AddWithValue怎么用?VB.NET SqlParameterCollection.AddWithValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlParameterCollection
的用法示例。
在下文中一共展示了SqlParameterCollection.AddWithValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: UpdateDemographics
Private Sub UpdateDemographics(ByVal customerID As Integer, _
ByVal demoXml As String, _
ByVal connectionString As String)
' Update the demographics for a store, which is stored
' in an xml column.
Dim commandText As String = _
"UPDATE Sales.Store SET Demographics = @demographics " _
& "WHERE CustomerID = @ID;"
Using connection As New SqlConnection(connectionString)
Dim command As New SqlCommand(commandText, connection)
' Add CustomerID parameter for WHERE clause.
command.Parameters.Add("@ID", SqlDbType.Int)
command.Parameters("@ID").Value = customerID
' Use AddWithValue to assign Demographics.
' SQL Server will implicitly convert strings into XML.
command.Parameters.AddWithValue("@demographics", demoXml)
Try
connection.Open()
Dim rowsAffected As Integer = command.ExecuteNonQuery()
Console.WriteLine("RowsAffected: {0}", rowsAffected)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Using
End Sub