我正在尝试使用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事件探查器跟踪:
declare @p1 int
set @p1=16
exec dbo.insert_Command @p1 output,'Name',NULL
select @p1
我的问题是为什么命令在sql语句中生成参数@ p1。这导致逻辑改变,因为我试图插入记录,如果参数id为null。
有关为何发生这种情况的任何建议?
提前致谢