当尝试从C ++在sql server中执行存储过程时,我得到ce = {DB_E_ERRORSINCOMMAND}

C ++代码是

pCom->Execute(NULL,NULL,adCmdStoredProc);


从命令对象执行。

存储过程如下所示

create PROCEDURE [dbo].[InsertTicketDetails]
AS
BEGIN
DECLARE @inputXml XML;
SET NOCOUNT ON
set @inputXml = '<Record><studentid>143</studentid></Record>';

INSERT INTO dbo.sample (studentid)
    SELECT
        @inputXml.value( 'studentid[1]', 'int' ) AS studentid
    FROM @inputXml.nodes('/Record') a(y)
END


如果在没有xml正常工作的情况下完成插入,则插入是通过xml完成​​的。我认为这是xml的问题,还是我们无法从C ++访问sql server的xml功能?

最佳答案

该错误不在ADO中,而是在返回NULL的SQL中。我怀疑dbo.sample(studentid)不允许为空。

将插入语句更改为:

INSERT INTO dbo.sample (studentid)
SELECT
    @inputXml.value( '(/Record/studentid)[1]', 'int' ) AS studentid


要么

INSERT INTO dbo.sample (studentid)
SELECT
    @inputXml.value( '(//studentid)[1]', 'int' ) AS studentid
FROM @inputXml.nodes('/Record') a(y)

关于c++ - ADO在存储过程中不支持XML,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10943357/

10-17 02:14