开发者

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

开发者 https://www.devze.com 2023-02-23 02:41 出处:网络
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). It is an UPDATE command. How do I conve

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). It is an UPDATE command. How do I convert and run this in 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
0

精彩评论

暂无评论...
验证码 换一张
取 消