繁体   English   中英

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

[英]How do I run this SQL query in 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

尝试这个

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