插入一条记录出错
我写了一个简单的数据库插入程序,分别插入姓名和年龄 ,用ado调用存储过程但是只能插入一个汉字或以字母为姓名的记录,如,只能插入 张 12 不能插入 张三 12,或 akdfg 12
CREATE PROCEDURE [Insert_Item]
@strName [char](8),
@iAge [int]
AS
insert into Demo([username] , [userage]) values(@strName ,@iAge)
GO
_CommandPtr spCmd; spCmd.CreateInstance( __uuidof(Command) ); spCmd->ActiveConnection = theApp.m_spConnection; //spCmd->CommandText = /*(LPCTSTR)strCmd;*/_T("Insert_Item"); //spCmd->CommandType ; //调用储存过程 _ParameterPtr param; param = spCmd->CreateParameter("" , adChar , adParamInput,strName.GetLength() + 1 , _variant_t(strName)); spCmd->Parameters->Append(param) ; param = spCmd->CreateParameter( "" , adInteger , adParamInput , sizeof(BYTE) + 1 , (BYTE)(iAge)) ; spCmd->Parameters->Append(param); spCmd->CommandText = _bstr_t(_T("Insert_Item")) ; spCmd->CommandType = adCmdStoredProc ; try { spCmd->Execute( NULL , NULL , adCmdStoredProc) ; /*spCmd->Execute( NULL, NULL, adCmdText );*/ } catch( _com_error& e ) { AfxMessageBox( e.ErrorMessage() ); return; }