如何在 VB.NET 中运行此 SQL 查询? [英] How do I run this SQL query in VB.NET?

查看:26
本文介绍了如何在 VB.NET 中运行此 SQL 查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SQL Server 2008 并且我的查询成功运行,现在我的要求是在 VB.NET (Visual Studio 2010) 中执行此代码.这是一个 UPDATE 命令.如何在 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). 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

推荐答案

试试这个

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

这篇关于如何在 VB.NET 中运行此 SQL 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆