简体   繁体   English

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

[英]How do I run this SQL query in VB.NET?

I'm using SQL Server 2008 and I have this query working successfully, Now my requirement is to execute this code in VB.NET (Visual Studio 2010). 我正在使用SQL Server 2008,并且该查询已成功运行,现在我的要求是在VB.NET(Visual Studio 2010)中执行此代码。 It is an UPDATE command. 这是一个UPDATE命令。 How do I convert and run this in VB.NET? 如何转换并在VB.NET中运行它?

DECLARE @Rt int
SET @Rt = 0

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

Try this 尝试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM