开发者

Re-using parameters in Ole DB?

I'm writing an Ole DB command and I need to repeat one particular parameter. Basically the situation is that I can't control the parameters that are passed in (this is handled by a (horrible) framework) and I can not create a stored procedure.

The query looks something like

DELETE FROM dbo.MyTable WHERE MyId = ? ;

INSERT INTO dbo.MyTable (MyId, SomeValue, SomeOtherValue) 
VALUES (?,?,?)

Problem is that the framework will only ever pass in the values for MyId, SomeValue and SomeOtherValue (in that order). Is there some way I can "use" that MyId value in the delete and still be able to access it again 开发者_如何学编程for the insert?

The backing DB is IBM DB2 if it's relevant.


No, for OLE DB connections, the ? maps to one parameter only once. That's one of the advantages of using the ADO.NET provider is that it uses named parameters.

Since you state you can modify the query, then it should be easy, just mix and match. Use the OLE DB parameters to assign to a local variable like so

DECLARE @MyId int
SET @MyId = ?
DELETE FROM dbo.MyTable WHERE MyId = @myid ;

INSERT INTO dbo.MyTable (MyId, SomeValue, SomeOtherValue) 
VALUES (@myId,?,?)

I don't have a DB2 instance any more or I'd very it works but it ought to...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜