ok this a have this problem thats bugging me for 2 weeks and i couldn't find a solution to this.
hopefully someone can enlighten me. Thanks in advance!
the story goes :
i have written a MFC to call on a few stored procedures i have in SQL server.
the 1st sp
CREATE PROCEDURE sp_Remove_Particulars
(
@student_ID int
)
as
begin
Delete from App_Student
where ID = @student_ID
Delete from Sys_Student_Subject
where student_subject_ID = @student_ID
Delete from Sys_Student_Class
where Student_Class_ID = @student_ID
end
2nd sp
CREATE PROCEDURE sp_Edit_Particulars
(
@Student_ID int,
@cClass char(1)
)
as
begin ( and so on..)
the command codes in VC++ :
the program can successfully call on the 1st sp but fails for the second one
(i suspect its smthing to do with the
as u can see the 1st sp calls for one "input" namely the IDCode:void CADOMFC1View::OnMenuitem32772() { _CommandPtr pCommand; pCommand.CreateInstance(__uuidof( Command )); CADOMFC1Doc * pDoc; pDoc = GetDocument(); try { pCommand->ActiveConnection = pDoc->m_pConnection; pCommand->CommandType = adCmdStoredProc; pCommand->CommandText = _bstr_t("sp_Remove_Particulars"); VARIANT vIntegerType; vIntegerType.vt = VT_I2; //Variant type for Integer vIntegerType.intVal = 32; pCommand->Parameters->Append(pCommand->CreateParameter(_bstr_t("student_ID"),adInteger,adParamInput,4,vIntegerType)); _variant_t vNull; vNull.vt = VT_ERROR; vNull.scode = DISP_E_PARAMNOTFOUND; pCommand->Execute(NULL,NULL,adCmdStoredProc); AfxMessageBox("Data Removed Successfully"); } catch( _com_error &e ) { TRACE( "Error:%08lx.\n", e.Error()); TRACE( "ErrorMessage:%s.\n", e.ErrorMessage()); TRACE( "Source:%s.\n", (LPCTSTR) _bstr_t(e.Source())); TRACE( "Description:%s.\n", (LPCTSTR) _bstr_t(e.Description())); } catch(...) { TRACE( "\n*** Unhandled Exception ***\n" ); } } void CADOMFC1View::OnMenuitem32773() { _CommandPtr pCommand; pCommand.CreateInstance(__uuidof( Command )); CADOMFC1Doc * pDoc; pDoc = GetDocument(); try { pCommand->ActiveConnection = pDoc->m_pConnection; pCommand->CommandType = adCmdStoredProc; pCommand->CommandText = _bstr_t("sp_Edit_Particulars"); VARIANT vInteger; vInteger.vt = VT_I2; //Variant type for Integer vInteger.intVal = 33; VARIANT cClass; cClass.vt = VT_BSTR; //Variant type for BSTR cClass.bstrVal = _bstr_t("Class"); pCommand->Parameters->Append(pCommand->CreateParameter(_bstr_t("Student_ID"),adInteger,adParamInput,4,vInteger)); pCommand->Parameters->Append(pCommand->CreateParameter(_bstr_t("cClass"),adChar,adParamInput,2,cClass)); _variant_t vNull; vNull.vt = VT_ERROR; vNull.scode = DISP_E_PARAMNOTFOUND; pCommand->Execute(NULL,NULL,adCmdStoredProc); AfxMessageBox("Data Edited Successfully"); } catch( _com_error &e ) { TRACE( "Error:%08lx.\n", e.Error()); TRACE( "ErrorMessage:%s.\n", e.ErrorMessage()); TRACE( "Source:%s.\n", (LPCTSTR) _bstr_t(e.Source())); TRACE( "Description:%s.\n", (LPCTSTR) _bstr_t(e.Description())); } catch(...) { TRACE( "\n*** Unhandled Exception ***\n" ); // TRACE(e.Description()); } }
but the second one calls for two inputs.
i tried using variant type for char but i didnt worked so i kept to BSTR.
the program compiles w/o errors.
but when i run the program only the 1st command works
the 2nd one just edited my "class" incorrectly
i just changed the @cClass char(1) to @cClass char(100)
and pCommand->Parameters->Append(pCommand->CreateParameter(_bstr_t("cClass"),adChar,adParamI nput,2,cClass));
to
pCommand->Parameters->Append(pCommand->CreateParameter(_bstr_t("cClass"),adChar,adParamI nput,100,cClass));
and it replaced my "class" data with 'Student_ID'



LinkBack URL
About LinkBacks


