如何在VB.NET中运行此SQL查询?

时间:2011-04-10 08:14:17

标签: sql vb.net

我正在使用SQL Server 2008并且我已成功运行此查询,现在我的要求是在VB.NET(Visual Studio 2010)中执行此代码。这是一个UPDATE命令。如何在VB.NET中转换并运行它?

DECLARE @Rt int
SET @Rt = 0

UPDATE DB.dbo.Sales
SET @Rt = Total = @Rt + Area1 + Area2
FROM DB.dbo.Sales

1 个答案:

答案 0 :(得分:7)

试试这个

Dim query as string = "UPDATE DB.dbo.Sales SET @Rt = Total = @Rt + Area1 + Area2 FROM Sales"
Dim updateCommand as new SqlCommand(query, SqlConnection)
updateCommand.Parameters.AddWithValue("@rt",0)
If 0 <> updateCommand.ExecuteNonQuery() Then 'Number of rows affected by the query
'Update command was successfull.
End If