0

我正在尝试使用 c++ 使用 adodb 将记录插入表中。

存储过程:

CREATE PROCEDURE [dbo].[dbo.insert_command]
  @Id INT OUTPUT,
  @Name    varchar(25),
  @Age   int = NULL
  -- WITH ENCRYPTION
AS
...

声明命令:

TESTHR(m_pInsertCommand.CreateInstance(__uuidof(Command)));
    m_pInsertCommand>ActiveConnection = m_pConnection;
    m_pInsertCommand>CommandText = L"dbo.insert_command";
    m_pInsertCommand>Parameters->Append(m_pInsertCommand->CreateParameter(L"Id", adInteger, adParamOutput, 4, vtNull));
    m_pInsertCommand>Parameters->Append(m_pInsertCommand->CreateParameter(L"Name", adVarChar, adParamInput, m_lLabelLength));
    m_pInsertCommand>Parameters->Append(m_pInsertCommand->CreateParameter(L"Age", adInteger, adParamInput, sizeof(long), vtNull));

设置参数:

dbConnection.m_pInsertCommand->Parameters->Item[L"Id"]->Value = vtNull;
dbConnection.m_pInsertCommand->Parameters->Item[L"Name"]->Value = (BSTR) m_Name;
dbConnection.ExecuteCommand(dbConnection.m_pInsertCommand, adCmdStoredProc | adExecuteNoRecords);
Id = (long) dbConnection.m_pInsertDefectCommand->Parameters->Item[L"Id"]->Value;

通过 SQL Profiler 跟踪:

declare @p1 int
set @p1=16
exec dbo.insert_Command @p1 output,'Name',NULL
select @p1

我的问题是为什么命令在sql语句中生成参数@p1。如果参数 id 为空,这会导致逻辑发生变化,因为我试图插入一条记录。

关于为什么会发生这种情况的任何建议?

提前致谢

4

0 回答 0