开发者

Using Multiple T-SQL Statements in ADO.NET

开发者 https://www.devze.com 2022-12-13 13:05 出处:网络
Scripting in management studio with T-SQL works very well, but I am having a question about ADO.NET. I am able to code a simple select statement in ado.net.

Scripting in management studio with T-SQL works very well, but I am having a question about ADO.NET.

I am able to code a simple select statement in ado.net.

How to use the set statement in ado.net ?

e.g.

SET @polygon = (SELECT GEOM FROM Polygons W开发者_如何学GoHERE NAME = 'Area1');
SELECT NAME FROM Points WHERE @polygon.STDistance(GEOM) <= .4;


If you put that in one big sql string that you assign to an SqlCommand object's command text and run in one function call, it should run fine: just like it would in management studio.

If you try to run it in two seperate SqlCommand objects or run over SqlCommand function calls, the 2nd command won't know anything about the first anymore.


You can include multiple commands in a single ADO.NET SqlCommand simply by separating them with semicolons.

However, I would recommend using a stored procedure for this kind of thing instead.

0

精彩评论

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

关注公众号