[BTS][收藏]使用SqlAdapter插入数据并得到ID号
2007-05-12 21:47
471 查看
Get row identity from SQL Adapter response
Recently I had to insert a record using a stored procedure and the SQL Adapter in BizTalk 2006. There are lots of examples on both how to insert records and how to select a number of record using this adapter. However I had problems finding how to insert a record and receiving the new id of the inserted row in return (the SCOPE_IDENTITY()). In my scenario I needed the id to insert into another database further down in the orchestration.
I ended up with a stored procedure looking like the below.
The trick was to use the XML RAW Mode. This mode transforms the result set into a generic identifier as <row>. It is however possible to provide a element name, as <Response>. Basically this will insert the new value and return something like this from the stored procedure.
After return via the send port the orchestration will receive something like the below.
The schema that I use to both handling the response and request against the SQL Adapter is shown below. First I set the type of the Id-attribute to xs:int but this gave me some problems when using the promoted value in the orchestration, everything worked fine when switching back to xs:string.
![](http://richardhallgren.com/blog/wp-content/uploads/2007/04/WindowsLiveWriter/GetrowidentityfromSQLAdapterresponse_D964/sqlinsertschema_thumb%5B12%5D2.jpg)
The same technique would be used for receiving a code from the stored procedure (say 1 for success and 0 for failure or whatever) and then to make a logical decision in the orchestration.
hehe,我自己也有自己的处理方法。方法与这个差不多。不过,现在这个方法更方便:)
Recently I had to insert a record using a stored procedure and the SQL Adapter in BizTalk 2006. There are lots of examples on both how to insert records and how to select a number of record using this adapter. However I had problems finding how to insert a record and receiving the new id of the inserted row in return (the SCOPE_IDENTITY()). In my scenario I needed the id to insert into another database further down in the orchestration.
I ended up with a stored procedure looking like the below.
ALTER PROCEDURE [dbo].[TestInsertParty] @partyName nchar(30) = NULL AS BEGIN SET NOCOUNT ON; Insert Into Party ([name], chain_idx) Values(@partyName, NULL) Select Scope_Identity() As Id For Xml Raw (‘Response‘) END
The trick was to use the XML RAW Mode. This mode transforms the result set into a generic identifier as <row>. It is however possible to provide a element name, as <Response>. Basically this will insert the new value and return something like this from the stored procedure.
<Response Id="1054" />
After return via the send port the orchestration will receive something like the below.
<TestInsertResponse xmlns="TestInsert"><Response Id="1054" /></TestInsertResponse>
The schema that I use to both handling the response and request against the SQL Adapter is shown below. First I set the type of the Id-attribute to xs:int but this gave me some problems when using the promoted value in the orchestration, everything worked fine when switching back to xs:string.
![](http://richardhallgren.com/blog/wp-content/uploads/2007/04/WindowsLiveWriter/GetrowidentityfromSQLAdapterresponse_D964/sqlinsertschema_thumb%5B12%5D2.jpg)
The same technique would be used for receiving a code from the stored procedure (say 1 for success and 0 for failure or whatever) and then to make a logical decision in the orchestration.
hehe,我自己也有自己的处理方法。方法与这个差不多。不过,现在这个方法更方便:)
相关文章推荐
- 在oracle中插入一条数据,id自动增长,插入之后怎么得到这个id(sequence的使用)
- 在oracle中插入一条数据,id自动增长,插入之后怎么得到这个id(sequence的使用)
- 不使用框架的情况下 如何得到刚插入的数据(ID自增)
- 在oracle中插入一条数据,id自动增长,插入之后怎么得到这个id(sequence的使用)
- 在oracle中插入一条数据,id自动增长,插入之后怎么得到这个id(sequence的使用)
- oracle中插入一条数据,id自动增长,插入之后怎么得到这个id(sequence的使用)
- yii 数据save后得到插入id
- sql中得到刚刚插入的数据的id
- C#中使用MySqlCommand执行插入语句后获取该数据主键id值的方法
- 使用mybatis的insert语句插入数据的时候,获取插入数据的主键id
- 得到刚刚插入数据库数据的主键ID
- 两种方法得到上次插入数据的ID
- 使用LKDBHelper 插入相同id时候应该是更新数据而不是插入新的数据
- 请问一下,我要向一个表插入数据,根据ID,重复的更新,没有的插入,不使用COUNT后判断,能做到吗?
- hibernate怎么得到插入数据的主键 或者自动增值的id
- 解析sql中得到刚刚插入的数据的id
- 在基于Mybatis持久层框架,使用数据库事务时,插入一条数据后,无法返回主键ID的问题研究
- yii 数据save后得到插入id
- 使用SQLiteHelper创建数据库并插入数据 分类: H1_ANDROID 2013-11-05 22:44 1398人阅读 评论(0) 收藏
- 插入一条数据,得到该数据的主键Id